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(
'login' => Array(
'type' => 'inputText',
'displayname' => 'Login name, min. 5, max. 15 chars',
'help' => 'The login name has to be at least 5 characters long, and must not be longer than 15 characters',
validation => Array(
Array(
'type' => 'string',
'minimum' => 5,
'maximum' => 15,
),
),
),
'password' => Array(
'type' => 'inputPassword',
'displayname' => 'Password, min. 5, max. 15 chars',
'help' => 'The password has to be at least 5 characters long, and must not be longer than 15 characters',
validation => Array(
Array(
'type' => 'string',
'minimum' => 5,
'maximum' => 15,
),
),
),
'passwordverify' => Array(
'type' => 'inputPassword',
'displayname' => 'Password again',
'help' => 'The two passwords has to be the same',
validation => Array(
Array(
'type' => 'string',
'equals' => 'password',
),
),
),
'email' => Array(
'type' => 'inputText',
'displayname' => 'Your e-mail address',
'help' => 'A valid e-mail address is required',
validation => Array(
Array(
'type' => 'string',
// an e-mail address format verification
// regular expression
'regexp' => '/^[\._0-9a-z-]+@[0-9a-z][-0-9a-z\.]*\.[a-z]{2,4}$/'
),
),
),
'categoryid' => Array(
'type' => 'selectDynamic',
'displayname' => 'This is a dynamic select created from a<br>typical tree-structured database table',
'sql' => 'SELECT id, name FROM portfolio_categories',
values =>
Array(
0 => '--- choose something from this list! ---',
),
'treeid' => 'id',
'treestart' => '0',
'treeparent' => 'parentid',
'help' => 'Please choose a category!',
validation => Array(
Array( 'type' => 'required' ),
Array( 'type' => 'number', 'minimum' => 1 )
),
),
'inputRadio' => Array(
'type' => 'inputRadio',
'displayname' => 'radiobutton group',
values => Array( 0 => 'no', 1 => 'yes', 2 => 'maybe' ),
validation => Array(
Array( 'type' => 'required' ),
),
),
'fulldateiso' => Array(
'type' => 'inputText',
'displayname' => 'Date YYYY-MM-DD (ISO)',
'value' => '2010-13-32',
validation => Array(
Array(
'type' => 'date',
'format' => 'YYYY-MM-DD',
),
),
),
'intmin5' => Array(
'type' => 'inputText',
'displayname' => 'Some number >= 5 ',
'help' => 'The value of the number field must be >= 5!',
validation => Array(
Array(
'type' => 'number',
'minimum' => 5,
),
),
),
'inputfile' => Array(
'type' => 'inputFile',
'displayname' => 'inputFile<br>with a <code>thumbnail</code>,<br> a <code>href</code> and a <code>delete</code> button',
'href' => BASE_URI . 'files/inputfile.png',
'thumbnail' => BASE_URI . 'files/inputfile_thumb.png',
'delete' => 'somescript.php?target=delete&filename=inputfile_thumb.png',
validation => Array(
Array(
'type' => 'file',
'types' => Array( 'jpgrgb' )
)
),
),
'selectfile[]' => Array(
'type' => 'selectFile',
'displayname' => 'selectFile - only one directory, full path, multiple',
'directory' => BASE_PATH . 'files/selectfile/',
'html' => 'multiple="multiple"',
'tree' => 0,
'includedirs' => 1,
),
);
?>
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>";
?>