* @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' => 'yes',
'display' => 'yes',
'edit' => 'yes',
'label' => 'Username',
'title' => 'Username',
'description' => 'Please enter your name here',
),
),
);
// create the form
$form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
// register the event handler for the onSubmit event - in this case,
// a custom function.
$form->registerEventHandler( 'onError', 'myDisplayErrors' );
/**
* Simple event handler that displays the errors.
*
* @access public
* @param object patForms form object
* @param string event name
* @return mixed any value your function should return. You will get the value as a return value of patForms::renderForm()
* @see patForms::registerEventHandler()
*/
function myDisplayErrors( &$form, $event )
{
// get and display errors as needed
$errors = $form->getValidationErrors();
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 ""; } } // 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(); // DISPLAY FORM ------------------------------------------------------ displayForm( $form, $elements ); // see patExampleGen/customFunctions.php // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>