* @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'];
// as we do not create a parser object and just call the parser's
// static methods, any needed options have to be called statically
// too, like setting the namespace or the cache folder to use:
patForms_Parser::setNamespace( "patForms" );
patForms_Parser::setCacheDir( "cache" );
// this method creates a complete patForms object in just one call,
// by setting the renderer to use, the source form template file,
// and the optional target template file.
$form =& patForms_Parser::createFormFromTemplate(
'SimpleRenderer',
'templates/example_parser_simple.fhtml',
'templates/example_parser_simple.html'
);
// use auto-validation
$form->setAutoValidate( 'save' );
// 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.