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
$info = 'Some extra layout with the "template" input type.
Note the <code>display => 0</code> parameters in
the configuration! This helps creating complex
form layouts while it\'s still easy to validate and edit.
';
$different_rowlayout =
'<tr %errorstyle%>'.
'<td>%element%</td>'.
'<td><label for="%id%">%displayname%</label></td>'.
'</tr>';
$config = Array(
'name' => Array(
'type' => 'inputText',
'displayname' => 'Your name',
),
'email' => Array(
'type' => 'inputText',
'displayname' => 'Your e-mail address',
),
'newsletter' => Array(
'type' => 'inputCheckbox',
'display' => 0,
'displayname' => 'Do you want to receive our free newsletter?',
'rowlayout' => $different_rowlayout,
),
'really' => Array(
'type' => 'inputCheckbox',
'display' => 0,
'displayname' => 'Do you REALLY want to receive our free newsletter?',
'rowlayout' => $different_rowlayout,
),
'marketing' => Array(
'type' => 'inputCheckbox',
'display' => 0,
'displayname' => 'May we contact you for marketing purposes?',
'rowlayout' => $different_rowlayout,
'value' => 'Y',
'onvalue' => 'Y',
'offvalue' => 'N',
),
'template' => Array(
'type' => 'template',
'value' =>
'<table>' .
'%newsletter%' .
'%really%' .
'%marketing%' .
'</table>'
),
'' => Array(
'type' => 'textarea',
'displayname' => 'Your comments',
'html' => 'cols="20" rows="5"',
),
);
?>
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>";
?>