* @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( 'area' => array( 'type' => 'Enum', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Area', 'title' => 'Area', 'style' => 'width:200px;', 'description' => 'Choose the area to access here.', 'values' => array(), ), ), ); // create the form $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); // DATASOURCE SETUP ------------------------------------------------------ /** * Very simple example for a datasource class for patForms elements that support * external data sources, like the Enum element. * * $Id: example_datasrc_object.php 394 2007-06-17 20:04:18Z gerd $ * * @access public * @package patForms * @subpackage Examples * @author Sebastian Mordziol * @license LGPL, see license.txt for details * @link http://www.php-tools.net * @see example.php */ class exampleDatasrc { var $values = array( array( "label" => "Please select...", "value" => "", ), array( "label" => "-----------", "value" => "", ), array( "label" => "Private Area", "value" => "a1", ), array( "label" => "Area 51", "value" => "a2", ), array( "label" => "Secluded experimental Mojave Area", "value" => "a3", ), ); /** * method for retrieving the values for the element, has to return them as * key => value pairs in an array. * * @access public * @return array $values The values for the element. */ function getValues() { return $this->values; } } // get the element $el =& $form->getElementByName( 'area' ); // instantiate the example data source $datasrcObject = new exampleDatasrc; // tell the element to use the datasource object $el->setDataSource( $datasrcObject ); // PROCESS FORM ------------------------------------------------------ // 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(); ?>