* @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( 'user' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Username', 'title' => 'Username', 'description' => 'Please enter your username here.', ), ), 'email' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Email', 'title' => 'Email', 'description' => 'Please enter your email address here.', 'format' => 'email', ), ), 'pass' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'label' => 'Password', 'title' => 'Password (Max. [ELEMENT_MAXLENGTH] / Min. [ELEMENT_MINLENGTH] chars)', 'type' => 'password', 'maxlength' => '8', 'minlength' => '6', 'description' => 'Please enter your password here (Max. [ELEMENT_MAXLENGTH] / Min. [ELEMENT_MINLENGTH] chars).', ), ), ); // create the form $form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); // create the needed renderer $renderer =& patForms::createRenderer( "Array" ); // set the renderer $form->setRenderer( $renderer ); // use auto-validation $form->setAutoValidate( 'save' ); // create the storage object - in this case, the DB storage // that can read/write data from/to a database. $storage =& patForms::createStorage( 'DB' ); // set the needed options for the storage object. Note that the DB // storage object needs PEAR::DB to work, so you have to make sure // that's present on your system. $storage->setStorageLocation( 'mysql://root:@localhost/pat', 'patForms_Storage' ); $storage->setPrimaryField( array( 'user' ) ); $storage->setFieldMap( array( 'user' => 'user', 'pass' => 'password', 'email' => 'email' ) ); // tell the form to use the storage object we just created. // That's all you need to do, the storage will handle $form->setStorage( $storage ); // if you want a specific record to be loaded on startup, you // just have to set the value of the primary field (the "user" // element here) to an existing value. $el =& $form->getElementByName( 'user' ); // set the default value to load an entry. If you want to test this feature, // simply add the user you set here by submitting the form - the entry will // be created, and the next time you call the form it will already be filled. $el->setAttribute( 'default', 'someuser' ); // serialize the elements $elements = $form->renderForm(); if (patErrorManager::isError($elements)) { echo '
';
		print_r($elements->getMessage());
		echo '
'; } // ERROR DISPLAY ------------------------------------------------------ if( $form->isSubmitted() ) { displayErrors( $form ); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ displayForm( $form, $elements ); // see patExampleGen/customFunctions.php // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>