Step 2: Editing with GridlessBuilder.js

Example file: example2.php.

To use GridlessBuilder.js, include the css in the <head> section:

<link href="dist/gridlessbuilder.css" rel="stylesheet" type="text/css" />

and include the scripts before the end of the <body> tag.

<script src="assets/lang/en.js"></script>  <!-- language file -->
<script src="dist/gridlessbuilder.min.js"></script>

Important: when using GridlessBuilder.js for editing, you don’t need to include grildless.js. It is used only for viewing content (in production).

Viewing:

gridless.css

gridless.js

Editing:

gridless.css

gridlessbuilder.css

gridlessbuilder.js

In our CMS, we will use AJAX to submit the edited content, but for now, let’s see how to use GridlessBuilder.js with a simple HTML form to submit the content.

<form id="frmContent" method="post" enctype="multipart/form-data">
	<input id="hidId" name="hidId" type="hidden" value="<?php echo $id; ?>" />
	<input id="hidContent" name="hidContent" type="hidden" />
	<input id="hidCss" name="hidCss" type="hidden" />
	<input id="hidJs" name="hidJs" type="hidden" />
</form>

Here we prepare a form that has 4 hidden fields. The edited content, css and js will be transfered to these fields so that the values can be submitted to the server. The page id ($id) value is also submitted to tell which page record should be updated.

Now we initialize GridlessBuilder.js for editing the content inside <div class=”is-wrapper”>.

<script>
    var obj = new GridlessBuilder({
        wrapper: '.is-wrapper', 
        onSave: function() {
            var html = obj.html();
            var css = obj.styles();
            var js = obj.js();
            document.querySelector('#hidContent').value = html;
            document.querySelector('#hidCss').value = css;
            document.querySelector('#hidJs').value = js;            
            document.querySelector('#frmContent').submit();
        }
    });
</script>

Inside the onSave function, we get the edited content, css and js using html(), css() and js() methods. Then we set our form fields with the values and submit the form.

On the server side, an sql update is performed using the submitted data.

<?php
...
$id = $_POST['hidId'];
$content = $_POST['hidContent'];
$css = $_POST['hidCss'];
$js = $_POST['hidJs'];

$sql = 'UPDATE pages set content= :content, css= :css, js= :js where id= :id';	
$s = $pdo->prepare($sql);
$s->bindValue(':content', $content);
$s->bindValue(':css', $css);
$s->bindValue(':js', $js);
$s->bindValue(':id', $id);		
$s->execute(); 
...
?>

For the complete code and to try the example, please open example2.php.

http://localhost/mysite/example2.php

The builder with blank section will be shown.

To save the content, click the Save button as shown in the screenshot below. It will trigger the onSave event.

About | Privacy | Delivery & Return

Copyright © 2021 Insite Mitra Inovindo. All Rights Reserved.

situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot situs slot slot gacor slot gacor slot gacor slot gacor slot gacor slot gacor bengbengtoto bengbengtoto bengbengtoto bengbengtoto bengbengtoto bengbengtoto toto slot toto slot cahayatoto cahayatoto cahayatoto jual toto jualtoto balaitoto mpo slot toto togel toto togel toto togel toto slot toto slot toto slot indosattoto toto slot indosattoto indosattoto jualtoto toto slot cahayatoto Nagihtoto Balaitoto Balaitoto Bengbengtoto Balaitoto Balaitoto Balaitoto Mineraltoto Mineraltoto Mineraltoto Mineraltoto Nagihtoto Mineraltoto indosattoto indosattoto ohtogel ohtogel indosattoto Indosattoto Nagihtoto toto togel toto togel situs slot slot gacor mineraltoto indosattoto toto slot slot gacor slot 4d situs slot toto togel slot online jualtoto jualtoto cahayatoto indosattoto mineraltoto sisi368 balaitoto balaitoto bandar togel situs togel toto togel slot gacor mineraltoto mineraltoto mineraltoto mineraltoto situs toto toto slot situs toto situs toto toto togel slot gacor balaitoto balaitoto mineraltoto mineraltoto ohtogel situs slot toto slot toto togel balaitoto toto togel cahayatoto cahayatoto Toto Slot Situs Resmi Slot Gacor Toto Slot toto togel sisi368 toto slot sisi368 bengbengtoto balaitoto mineraltoto Mineraltoto nagihtoto nagihtoto jualtoto sisi368 ohtogel ohtogel toto slot slot gacor bengbengtoto ohtogel nagihtoto nagihtoto mineraltoto mineraltoto situs togel situs togel situs slot mineraltoto toto togel slot gacor situs toto slot gacor