* @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' ) );
/**
* Simple event handler object that implements the onSuccess and onError
* forms events.
*
* @access public
* @package patForms
* @subpackage Examples
* @see patForms::registerEventHandlerObject()
*/
class myErrorHandler
{
/**
* Simple event handler that should store the values in a
* datasource.
*
* @access public
* @param object patForms The patForms object
* @param string $event The name of the event., e.g. 'onSuccess'
* @return mixed $result Any value your function should return. You will get the value as a return value of patForms::renderForm()
*/
function onSuccess( &$form, $event )
{
echo 'patForms: validation successful (onSuccess event handler triggered).
';
echo '
'; print_r( $form->getValues() ); echo ''; return true; } /** * Simple event handler that displays any errors. * * @access public * @param object patForms The patForms object, e.g. 'onSuccess' * @return mixed $result Any value your function should return. You will get the value as a return value of patForms::renderForm() */ function onError( &$form, $event ) { echo "patForms: validation failed (onError event handler triggered). Errors:
"; print_r( $elementErrors ); echo ""; } } } // instantiate the custom error handling object $errorHandler =& new myErrorHandler(); // register the event handling object $form->registerEventHandlerObject( $errorHandler ); // 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(); ?>