* @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']; /** * patForms parser class */ require_once $neededFiles['patForms_Parser']; /** * patErrorManager class */ require_once $neededFiles['patErrorManager']; /** * localisation stuff */ require_once $neededFiles['patI18n_configure']; // create the parser object via the available factory method. This // is important, as you have to define which renderer you want to // use to render the form. // // Note: the renderer you set here is a patForms_Parser renderer, you // cannot use the default patForms renderers. The renderers for the // parser are stored in the patForms/Parser/ folder of the patForms // distribution. $parser =& patForms_Parser::createParser( 'SimpleRenderer' ); // set the namespace we use for the patForms tags in the form template. // You have to set this so that the renderer knows which tags to parse. $parser->setNamespace( "patForms" ); // tell the parser to parse the form template. $parser->parseFile( "templates/example_parser_intro.fhtml" ); // you can retrieve the resulting HTML from the parser, which contains // placeholders for each of the defined form elements. This is the content // of the .tmpl file the parser creates during the earlier parseFile() call. // $html = $parser->getHTML(); // retrieve the fully configured patForms object from the parser. This // contains all elements retrieved from the form template. $form =& $parser->getForm(); // use auto-validation $form->setAutoValidate( 'save' ); // the form needs a renderer to render itself, so we just use the parser // itself as renderer. Remember that we set the SimpleRenderer as renderer // for the parser? $form->setRenderer( $parser ); // render the content into a variable, we will display it after // the validation output $content = $form->renderForm(); // check the form and display error messages if any if( $form->isSubmitted() ) { // get and display errors as needed. If no errors are found, // this will return false so it is easy to check. $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.

"; } } // now display the form echo $content; // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>