* @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',
),
),
'wishlist' => array(
'type' => 'Set',
'attributes' => array(
'required' => 'yes',
'display' => 'yes',
'edit' => 'yes',
'label' => 'Wishlist',
'title' => 'Wishlist',
'description' => 'Pick your wishes in the list.',
'size' => 'auto',
'maxsize' => 'none',
'max' => '4',
'min' => '2',
'values' => array(
array(
'label' => 'More patForms elements',
'value' => 'w1',
),
array(
'label' => 'Javascript validation',
'value' => 'w2'
),
array(
'label' => 'More J�erschnitzel',
'value' => 'w3'
),
array(
'label' => 'Soft green mushroom soup on sundays',
'value' => 'w4'
),
array(
'label' => 'A real axe for the Argh',
'value' => 'w5'
),
array(
'label' => 'Roasted chicken on demand',
'value' => 'w6'
),
array(
'label' => 'A tank',
'value' => 'w7'
),
),
),
),
);
// 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( 'onSuccess', 'storeForm' );
/**
* Simple event handler that could store the values in a
* datasource. In this case, it just displays the data.
*
* @access public
* @param object patForms The patForms object
* @param string $event The event type
* @return mixed $result Any value your function should return. You will get the value as a return value of patForms::renderForm()
* @see patForms::registerEventHandler()
*/
function storeForm( &$form, $event )
{
echo 'Event handler storeForm() has been called for event "on'.$event.'".
';
echo 'Form data:';
echo '
'; print_r( $form->getValues() ); echo ''; return true; } // 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 and display errors. For // convenience and also to keep the examples easy to understand, all // the following examples will use teh helper methods of the examples // framework to display the errors and the form. if( $form->isSubmitted() ) { displayErrors( $form ); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ displayForm( $form, $elements ); // see patExampleGen/customFunctions.php // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>