This plugin supports full PHP naming and deep data structures, as well as checkbox arrays and other non-standard UI controls. The plugin can be used as part of your AJAX toolkit, or for separating server-side code from HTML by populating a form after the page has loaded eg:
$('form').populate({'text':'text', 'radio':1})
and not inline as the page is processed, such as:
<input type="text" name="text" id="text" value="<?php echo $text; ?>" /> <input type="radio" name="radio" id="radio-1" checked="<?php echo $val == 1; ?>" /> <input type="radio" name="radio" id="radio-2" checked="<?php echo $val == 2; ?>" />
You can also populate non-form controls such as
$('div').populate({'text-1':'text', 'text-2':'More text'})
This can be useful when you want to show the results of a database call, but don’t want the text to be editable.
Just include the PHP JSON class, PHP helper function and of course Populate at the top of your page, and a PHP snippet such as this the bottom:
<?php populate('form', $data); ?/>
Which will output something meaningful like this:
I’ve now FINALLY put up a full set of instructions and a working demo, with examples of:
View the jQuery Populate Demo here.
JavaScript
PHP