* @license LGPL, see license.txt for details
* @link http://www.php-tools.net
*/
/**
* Main examples prepend file, needed *only* for the examples framework!
*/
include_once 'patExampleGen/prepend.php';
$exampleGen->displayHead( 'Example' );
// EXAMPLE START ------------------------------------------------------
/**
* main patForms class
*/
require_once $neededFiles['patForms'];
/**
* patErrorManager class
*/
require_once $neededFiles['patErrorManager'];
// element definitions for this example
$elementsDefinition = array(
'username' => array(
'type' => 'String',
'attributes' => array(
'required' => 'yes',
'display' => 'yes',
'edit' => 'yes',
'label' => 'Nickname',
'description' => 'Enter your nickname here.',
'maxlength' => '5',
'minlength' => '4',
'default' => 'The Argh',
'title' => 'Username',
),
),
);
echo 'Setting locale to gungan (gu), which are read from a file... validation errors ';
echo 'will be displayed in gungan.
';
// Set the locale to the custom locale 'gungan'.
patForms::setLocale( 'gu', 'locales/gungan.ini' );
// create our form
$form =& patForms::createForm( $elementsDefinition );
$rule = &patForms::createRule('Enum', 'myRule');
$rule->setValues(array('schst', 'argh', 'gerd'));
$el = &$form->getElementByName('username');
$el->addRule($rule);
// tell the form it has been submitted
$form->setSubmitted( true );
// validate the element - this will always fail here on purpose to show
// the error message
$form->validateForm();
// display the errors
displayErrors( $form ); // see patExampleGen/customFunctions.php
$form->setValues(array('username' => 'Fooo'));
// validate the element - this will always fail here on purpose to show
// the error message
$form->validateForm(true);
// display the errors
displayErrors( $form ); // see patExampleGen/customFunctions.php
// EXAMPLE END ------------------------------------------------------
$exampleGen->displayFooter();
?>