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(
'fulldateiso' => Array(
'type' => 'inputText',
'displayname' => 'Date YYYY-MM-DD (ISO)',
'value' => date("Y-m-d"),
'validation' => Array(
Array(
'type' => 'date',
'format' => 'YYYY-MM-DD',
),
),
),
'fulldateisogt' => Array(
'type' => 'inputText',
'displayname' => 'Date YYYY-MM-DD (ISO)',
'value' => date("Y-m-d"),
'postfix' => '<br />(must be greater than the previous field)',
'help' => 'The date in the second field must be YYYY-MM-DD and must be later than the date in the first one!',
'validation' => Array(
Array(
'type' => 'date',
'format' => 'YYYY-MM-DD',
'greaterthan' => 'fulldateiso'
),
),
),
'fulldate' => Array(
'type' => 'inputText',
'displayname' => 'Date MM/DD/YYYY',
'postfix' => '<br />(or leave it empty)',
'value' => date("m/d/Y"),
'validation' => Array(
Array(
'type' => 'date',
'format' => 'MM/DD/YYYY',
'required' => 0,
),
),
),
'fulltime' => Array(
'type' => 'inputText',
'displayname' => 'Timestamp YYYY-M-D h:m:s',
'value' => date("Y-m-d H:i:s"),
'postfix' => '<br />(minimum: 2000-01-01 13:00)',
'help' => 'Please use YYYY-M-D h:m:s format and a date >= 2001-01-01 13:00',
'validation' => Array(
Array(
'type' => 'date',
'format' => 'YYYY-M-D h:m:s',
'minimum' => strtotime('2001-01-01') + 13 * 60 * 60,
),
),
),
);
?>
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>";
?>