* @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 - note // that they are all grouped together in one // array, with the additional keys 'type' and // 'attributes'. $elementsDefinition = array( 'username' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Username', 'description' => 'Enter your username here. Maximum length: [ELEMENT_MAXLENGTH]', 'default' => 'argh', 'maxlength' => '15', 'minlength' => '4', 'title' => 'Username', ), ), 'password' => array( 'type' => 'String', 'attributes' => array( 'type' => 'password', 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Password', 'description' => 'Enter your password here. Maximum length: [ELEMENT_MAXLENGTH]', 'maxlength' => '15', 'minlength' => '4', 'title' => 'Password', ), ), ); // create the form - and just set the elements definition // directly here to have patForms automatically create and // add all needed elements. The attributes of the form itself // can also be set here directly (the name, for instance) $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); // create the needed renderer so patForms knows how to // display the elements. In this case the array renderer // is used, wich returns all serialized elements in an array. $renderer =& patForms::createRenderer( "Array" ); // give patForms the array renderer $form->setRenderer( $renderer ); $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', ), ) ); $area = &patForms::createElement('area', 'Enum', $attributes); $user = &$form->getElement('username'); $form->replaceElement($user, $area); $form->addElement($user); // serialize the elements using the array renderer - in this // array are contained all serialized elements along with their // attribute collection for easy access. You decide where and // what to display. $elements = $form->renderForm(); if( isset( $_POST['save'] ) ) { $form->setSubmitted( true ); $form->validateForm(); } // 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(); ?>