* @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' ) ); // create the observer we want to use - in this case, the // ErrorAttributes observer which enables you to set the // attributes collection the element will use if it is // not valid. $errAtt =& patForms::createObserver( 'ErrorAttributes' ); $errAtt->setAttributes( array( 'style' => 'background:#cc0000;color:#ffffff;' ) ); // attach the observer to the element $form->attachObserver( $errAtt, 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(); ?>