* @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' => 'no', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Your name', 'title' => 'Your name', 'description' => 'Enter your name here. Beware: only authorized personnel!', ), ), ); // 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 Enum rule, which enables // you to restrict the possible values that you can enter into the field. $enum = &patForms::createRule( 'Enum' ); // set the possible values for this rule $enum->setValues( array( 'schst', 'argh', 'gERD' ) ); // get the element $el =& $form->getElementByName( 'username' ); $url = &patForms::createRule('URL'); $el->addRule($url); $el->addRule($enum, PATFORMS_RULE_AFTER_VALIDATION); $el->removeRule($url); // 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(); ?>