* @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( 'password' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'type' => 'password', 'label' => 'Password', 'title' => 'Password', 'description' => 'Enter your password here. Maximum length: [ELEMENT_MAXLENGTH]', 'maxlength' => '15', 'minlength' => '4', ), ), 'retype' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'type' => 'password', 'label' => 'Password (retype)', 'description' => 'Re-Enter your password here.', 'maxlength' => '15', 'minlength' => '4', 'title' => 'Password (retype)', ), ), 'phone' => array( 'type' => 'String', 'attributes' => array( 'required' => 'no', 'display' => 'yes', 'edit' => 'yes', 'id' => 'phone', 'label' => 'Phone number', 'title' => 'Phone number', 'description' => 'Your phone number', ), ), 'email' => array( 'type' => 'String', 'attributes' => array( 'required' => 'no', 'display' => 'yes', 'edit' => 'yes', 'id' => 'email', 'label' => 'E-Mail address', 'title' => 'E-Mail address', 'description' => 'Your E-Mail address', ), ), ); // create the form $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); // create the needed renderer $renderer =& patForms::createRenderer( "Array" ); // set the renderer $form->setRenderer( $renderer ); // use auto-validation $form->setAutoValidate( 'save' ); // create the rule. In this case we use the retype rule to make // sure that the two password fields are identical. $retype = &patForms::createRule( 'Retype' ); // set which fields have to be identical $retype->setFieldNames( 'password', 'retype' ); // add the rule to the form. In this case, we want the rule to be // executed after all elements in the form have been validated, as // the comparison only makes sense then. $form->addRule( $retype, PATFORMS_RULE_AFTER_VALIDATION ); // create and add a second rule $required = &patForms::createRule('AnyRequired'); $required->setFieldNames(array('email', 'phone')); $form->addRule($required, PATFORMS_RULE_AFTER_VALIDATION); // serialize the elements $elements = $form->renderForm(); // ERROR DISPLAY ------------------------------------------------------ // ask the form if it has been submitted and display errors. For // convenience and also to keep the examples easy to understand, all // the following examples will use teh helper methods of the examples // framework to display the errors and the form. if( $form->isSubmitted() ) { displayErrors( $form ); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ displayForm( $form, $elements ); // see patExampleGen/customFunctions.php // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>