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
$config = Array(
'inputRadio1' => Array(
'type' => 'inputRadio',
'displayname' => 'inputRadio',
values => Array( 0 => 'no', 1 => 'yes', 2 => 'maybe' ),
),
'inputRadio2' => Array(
'type' => 'inputRadio',
'displayname' => 'inputRadio<br> with a default value',
values => Array( 0 => 'no', 1 => 'yes', 2 => 'maybe' ),
'value' => 0,
),
'inputRadio3' => Array(
'type' => 'inputRadio',
'displayname' => 'inputRadio<br> with tabular layout',
values => Array( 0 => 'no', 1 => 'yes', 2 => 'maybe' ),
'value' => 0,
'itemlayout' => '<tr><td>%radio%</td><td>%label%</td></tr>',
'layout' => '<table>%s</table>'
),
'inputRadio4' => Array(
'type' => 'inputRadio',
'displayname' => 'inputRadio<br> with a divider',
values => Array( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6' ),
'value' => 0,
'itemlayout' => '%radio% %label%<br />',
'layout' => '<table><tr><td> %s </td></tr></table>',
'divide' => 3,
'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>";
?>