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(
'fieldset' => Array(
'type' => 'fieldset',
'legend' => 'Online waiter',
'submit' => 1,
),
'wanttea' => Array(
'type' => 'inputRadio',
'displayname' => 'Would you like some tea?',
'values' => Array( 0 => 'no', 1 => 'yes' ),
'validation' => Array(
Array( 'type' => 'required' ),
),
),
'teaflavor' => Array(
'type' => 'inputRadio',
'displayname' => 'Choose a flavor!',
'values' => Array(
0 => 'almond',
1 => 'cherry',
2 => 'ginger',
3 => 'lemon',
4 => 'peach',
5 => 'vanilla',
),
'validation' => Array(
Array(
'anddepend' => Array(
Array(
'js' => '<FORM.wanttea> == 1',
'php' => '<FORM.wanttea> == 1',
)
),
'type' => 'required'
),
),
),
'wantcoffee' => Array(
'type' => 'inputRadio',
'displayname' => 'Some coffee?',
'values' => Array( 0 => 'no', 1 => 'yes' ),
'validation' => Array(
Array(
'anddepend' => Array(
Array(
'js' => '<FORM.wanttea> == 0',
'php' => '<FORM.wanttea> == 0',
)
),
'type' => 'required'
),
),
),
'addons' => Array(
'type' => 'inputCheckboxDynamic',
'displayname' => 'Addons',
'values' => Array(
'sugar' => 'sugar',
'brown sugar' => 'brown sugar',
'cream' => 'cream',
'milk' => 'milk',
),
'validation' => Array(
Array(
'ordepend' => Array(
Array(
'php' => '<FORM.wanttea> == 1',
'js' => '<FORM.wanttea> == 1'
),
Array(
'php' => '<FORM.wantcoffee> == 1',
'js' => '<FORM.wantcoffee> == 1'
),
),
'type' => 'required'
),
),
),
'custom' => Array(
'type' => 'select',
'displayname' => 'Please choose something else!',
'values' => Array(
0 => '',
1 => 'Coke',
2 => 'Orange juice',
3 => 'Mineral water',
4 => 'Energy drink',
),
'validation' => Array(
Array(
'anddepend' => Array(
Array(
'php' => '<FORM.wanttea> == 0',
'js' => '<FORM.wanttea> == 0'
),
Array(
'php' => '<FORM.wantcoffee> == 0',
'js' => '<FORM.wantcoffee> == 0'
),
),
'type' => 'number',
'minimum' => 1
),
),
),
);
?>
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>";
?>