* @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', 'label' => 'Username', 'description' => 'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]', 'title' => 'Username', ), ), 'password' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'label' => 'Password', 'type' => 'password', 'description' => 'Enter your password here. Maximum length: [ELEMENT_MAXLENGTH]', 'title' => 'Password', ) ), ); // default attributes we want to use $defaultAttributes = array( 'style' => 'width:100%', 'maxlength' => '15', 'minlength' => '4', ); // There are two ways to set the default attributes: // // 1. As a static function call (like we do here) before we create the form. // 2. As a normal function call after creating the form. // // Here we have to use the static function call before creating the form, as // we use the automatic element creation feature via the createForm() method, // and the default attributes have to be set before any element is created. patForms::setDefaultAttributes( $defaultAttributes ); // create the form $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); // use auto-validation $form->setAutoValidate( 'save' ); // create the needed renderer $renderer =& patForms::createRenderer( "Array" ); // set the renderer $form->setRenderer( $renderer ); // serialize the elements using the array renderer $elements = $form->renderForm(); // ERROR DISPLAY ------------------------------------------------------ // ask the form if it has been submitted and display errors if( $form->isSubmitted() ) { displayErrors( $form ); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ displayForm( $form, $elements ); // see patExampleGen/customFunctions.php // example footer $exampleGen->displayFooter(); ?>