This is the config array for clonefish which generates the form you've just seen. How can you use such an array?
<?php
$config = Array(
'categoryid' => Array(
'type' => 'selectDynamic',
'displayname' => 'This is a dynamic select - values come from an SQL query',
'sql' => 'SELECT id, name FROM portfolio_categories',
'values' =>
Array(
0 => 'choose nothing',
),
'treeid' => 'id',
'treestart' => '0',
'treeparent' => 'parentid',
),
'categoryids_withselect[]' => Array(
'type' => 'selectDynamic',
'displayname' => 'Multiple works too',
'html' => 'multiple="multiple"',
'sql' => 'SELECT id, name FROM portfolio_categories',
'treeid' => 'id',
'treestart' => '0',
'treeparent' => 'parentid',
'validation' => Array(
Array( 'type' => 'required' )
)
),
'categoryids_withcheckbox[]' => Array(
'type' => 'inputCheckboxDynamic',
'displayname' => 'How about a quite useful alternative to multiple selects with clever validation?',
'sql' => 'SELECT id, name FROM portfolio_categories',
'treeid' => 'id',
'treestart' => '0',
'treeparent' => 'parentid',
'validation' => Array(
Array( 'type' => 'required', 'minimum' => 3 )
)
),
'mapMarker' => Array(
'type' => 'mapmarker',
'displayname' => 'Address autocompletion and drag and drop marker!',
'key' => GOOGLE_API_KEY,
'jspath' => BASE_URI . 'js/',
),
);
?>
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>";
?>