* @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']; /** * localisation stuff */ require_once $neededFiles['patI18n_configure']; // element definitions for this example $elementsDefinition = array( 'username' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Username', 'title' => 'Username', 'description' => 'Please enter your username here.', ), ), 'userpass' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Password', 'title' => 'Password (Max. [ELEMENT_MAXLENGTH] / Min. [ELEMENT_MINLENGTH] chars)', 'type' => 'password', 'maxlength' => '8', 'minlength' => '6', 'description' => 'Please enter your password here (Max. [ELEMENT_MAXLENGTH] / Min. [ELEMENT_MINLENGTH] chars).', ), ), 'area' => array( 'type' => 'Enum', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Area', 'title' => 'Area', 'description' => 'Choose the area to access here.', 'values' => array( array( 'label' => 'Please choose an area...', 'value' => '', ), array( 'label' => 'Very pretty area', 'value' => 'a01', ), array( 'label' => 'No-nonsense area', 'value' => 'a02', ), ), ), ), ); // create the form $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); // output the styles we will be using here echo ''; // define the attributes collection we want to use when an element is // not valid. They don't make much sense at all, but I'm trying to make // a point here :) $errorAttributes = array( 'class' => 'errorField', 'description' => 'Please fix me, I\'m erroneous!' ); // create the error attributes observer $errAtt =& patForms::createObserver( 'ErrorAttributes' ); // set the attributes to use $errAtt->setAttributes( $errorAttributes ); // create the readonly observer $readOnly =& patForms::createObserver( 'ReadonlyFinished' ); // attach the observers to the elements $form->attachObserver( $errAtt, PATFORMS_OBSERVER_ATTACH_TO_ELEMENTS ); $form->attachObserver( $readOnly, PATFORMS_OBSERVER_ATTACH_TO_ELEMENTS ); // create the needed renderer $renderer =& patForms::createRenderer( "Array" ); // set the renderer $form->setRenderer( $renderer ); // use auto-validation $form->setAutoValidate( 'save' ); // serialize the elements $elements = $form->renderForm(); // ERROR DISPLAY ------------------------------------------------------ if( $form->isSubmitted() ) { displayErrors( $form ); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ displayForm( $form, $elements ); // see patExampleGen/customFunctions.php // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>