* @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 username here.',
),
),
'password' => array(
'type' => 'String',
'attributes' => array(
'required' => 'yes',
'display' => 'yes',
'edit' => 'yes',
'type' => 'password',
'label' => 'Password',
'title' => 'Password',
'description' => 'Please enter your password here.',
),
),
);
// create the form
$form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) );
// create the needed renderer - in this case we use the array renderer
// which is the most basic renderer that comes packaged with patForms.
// It renders all elements of the form into an array containing the
// complete attributes collection as well as the serialized element.
$renderer =& patForms::createRenderer( "Array" );
// set the renderer
$form->setRenderer( $renderer );
// use auto-validation
$form->setAutoValidate( 'save' );
// serialize the elements by telling the from to render it. In the case
// of the array renderer, this gives us the elements collection in one
// big array that we can use to display the information we need.
$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 ------------------------------------------------------
// output the opening form tag
echo $form->serializeStart();
// display all elements - as we use the array renderer, we have
// to do this manually by going through the elements collection
// coming from the renderer and displaying each.
foreach( $elements as $element )
{
echo $element["label"]."
";
echo "
'; print_r( $elements ); echo ''; // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>