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(
'number' => Array(
'type' => 'inputText',
'displayname' => 'Some integer number',
'validation' => Array(
Array(
'type' => 'number',
),
),
),
'sci' => Array(
'type' => 'inputText',
'displayname' => 'Even scientific notation!',
'value' => '13.02E13',
'validation' => Array(
Array(
'type' => 'number',
'real' => 'sci'
),
),
),
'intmin5' => Array(
'type' => 'inputText',
'displayname' => 'Some number >= 5 ',
'postfix' => '<br />you may also leave this field empty!',
'validation' => Array(
Array(
'type' => 'number',
'required' => 0,
'minimum' => 5,
),
),
),
);
?>
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>";
?>