* @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' ); /** * main patForms class */ require_once $neededFiles['patForms']; /** * patErrorManager class */ require_once $neededFiles['patErrorManager']; include dirname( __FILE__ ) . '/setup_gettext.php'; // element definitions for this example $elementsDefinition = array( 'xmess' => array( 'type' => 'Date', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'X-Mess eve', 'title' => 'X-Mess', 'description' => 'Tell me when you celebrate x-mess.', 'dateformat' => '%d.%m.%Y %H:%M', 'default' => '2001-12-24 07:30:42', 'onchange' => 'alert( pfe_xmess.getDate() )', ), ), ); // 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' ); // serialize the elements $elements = $form->renderForm(); // ERROR DISPLAY ------------------------------------------------------ // ask the form if it has been submitted if( $form->isSubmitted() ) { // get and display errors as needed $errors = $form->getValidationErrors(); if( $errors ) { echo "patForms: validation failed. Errors:

"; // each element can have several error messages. foreach( $errors as $elementName => $elementErrors ) { if( empty( $elementErrors ) ) continue; echo 'Field: '.$elementName.''; echo "
";
	            print_r( $elementErrors );
	            echo "
"; } } else { echo "patForms: validation successful.

"; } } // DISPLAY FORM ------------------------------------------------------ // output the opening form tag echo $form->serializeStart(); // display all elements foreach( $elements as $element ) { echo $element["label"]."
"; echo "
".$element["element"]."
"; echo "".$element["description"]."

"; } // submit button, closing form tag echo '

'; echo $form->serializeEnd(); // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>