Source
This is the config array for Clonefish
which generates the form you've just seen.
Scroll at the bottom of this window
to see how to use this array!
<?php
$info = 'inputCheckboxDynamic elements read their values and labels
from database using AdoDB, Pear DB or any other database wrapper -
just a simple line if the config array,
and your checkboxes are created dynamically! In this example
you\'ll even find a manually added checkbox ( "0 - no choice" ),
the other two options are coming from database.';
$config = Array(
'inputCheckboxDynamic' => Array(
'type' => 'inputCheckboxDynamic',
'displayname' => 'inputCheckboxDynamic',
'sql' => 'SELECT id, name FROM writers',
'valuesql' => 'SELECT id FROM writers',
),
'inputCheckboxDynamicDivider' => Array(
'type' => 'inputCheckboxDynamic',
'displayname' => 'inputCheckboxDynamic with divider',
'sql' => 'SELECT id, name FROM writers',
'valuesql' => 'SELECT id FROM writers',
'layout' => '<table><tr><td>%s</td></tr></table>',
'itemlayout' => '<nobr>%checkbox% %label%</nobr>',
'divide' => 4,
'divider' => '</td><td>',
),
);
?>
Usage example
To create a form using this array you'll only need
a few lines of code:
<?php
// create the form object
$clonefish = new clonefish( 'loginform', 'test.php', 'POST' );
// setup codepage so your data will be handled
// perfectly by the appropriate string functions
$clonefish->codepage = 'utf-8';
$clonefish->multibytesupport = 'multibyteutf8';
// add the form elements (fields) pre-filled with
// values from $_POST
$clonefish->addElements( $config, $_POST, get_magic_quotes_gpc() );
// validate the form if the form has been submitted
if ( count( $_POST ) && $clonefish->validate() ) {
// form is valid, go and store values in database, etc.
// $clonefish->getElementValues() provides a
// normalized value array.
}
else
// if the form wasn't submitted yet or the validation
// had failed, show the form (automatically
// including error messages)
echo
"<html><body>" .
$clonefish->getHTML() .
"</body></html>";
?>