* @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']; /** * patTemplate class */ require_once $neededFiles['patTemplate']; /** * localisation stuff */ require_once $neededFiles['patI18n_configure']; // element definitions for this example. Note that for each // the id attribute is set - the placeholders in the template // for the string renderer do not use an element's name, as // some elements have several subelements with the same name, // e.g. radio groups. $elementsDefinition = array( 'username' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'id' => 'user', 'label' => 'Username', 'title' => 'Username', 'description' => 'Please enter your username here.', ), ), 'email' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'id' => 'email', 'label' => 'E-Mail', 'title' => 'E-Mail', 'description' => 'Please enter your e-mail address here.', ), ), 'password' => array( 'type' => 'String', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'id' => 'pass', 'type' => 'password', 'label' => 'Password', 'title' => 'Password', 'description' => 'Please enter your password here.', ), ), 'birthday' => array( 'type' => 'Date', 'attributes' => array( 'required' => 'yes', 'display' => 'yes', 'edit' => 'yes', 'dateformat' => 'd.m.Y', 'id' => 'bd', 'label' => 'Your Birthday', 'description' => 'Please enter your birthday here.', ), ), ); // create the form $form =& patForms::createForm($elementsDefinition, array( 'name' => 'myForm' )); // create and add the rule that checks both // password fields $retype = patForms::createRule('Retype'); $retype->setFieldNames( 'password', 'password2' ); $form->addRule( $retype, PATFORMS_RULE_AFTER_VALIDATION ); // create the needed renderer - in this case we use the patTemplate renderer $renderer =& patForms::createRenderer('patTemplate'); // always use the same placeholder, as the template will be // repeated $renderer->setPlaceholder('PATFORMS_ELEMENT', null); // You could optionally create your own instance of patTemplate and // pass it to the renderer: // // $tmpl = &new patTemplate(); // $tmpl->setRoot('templates'); // $renderer->setTemplate($tmpl) // // If you do not pass a template object, the renderer will try // to instantiate its own template object // set the renderer $form->setRenderer($renderer); // use auto-validation $form->setAutoValidate('save'); $args = array( // directory, where the templates are stored 'tmplDir' => 'templates', // file that will be used to render the template 'tmplFile' => 'example_renderer_pattemplate_repeat.tmpl', // name of the template, to which the form tags will // be added. If you ommit this, addGlobalVar() will be used // instead of addVar() 'tmplName' => 'form', // name of the template, which will be used to render the // elements 'elementTemplate' => 'element', // if errors occured, the visibility of this template // will be set to 'visible' 'errorTemplateContainer' => 'errors', // errors will be added to this template 'errorTemplate' => 'error' ); $tmpl = &$form->renderForm($args); // DISPLAY FORM ------------------------------------------------------ $tmpl->displayParsedTemplate(); // EXAMPLE END ------------------------------------------------------ $exampleGen->displayFooter(); ?>