* @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)', '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 CSV storage // that can read/write data from/to a CSV textfile. $storage =& patForms::createStorage('CSV'); // set the needed options for the storage object $storage->setFile('./data/users.csv'); $storage->setPrimaryField('user'); $storage->setFieldOrder(array('user', 'email', 'pass')); // 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 from the specified file, // 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', 'anyuser'); // serialize the elements $elements = $form->renderForm(); // ERROR DISPLAY ------------------------------------------------------ if ($form->isSubmitted()) { displayErrors($form); // see patExampleGen/customFunctions.php } // DISPLAY FORM ------------------------------------------------------ displayForm($form, $elements); // see patExampleGen/customFunctions.php // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>