* @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.', ), ), '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.', ), ), ); // create the form $form =& patForms::createForm($elementsDefinition, array( 'name' => 'myForm' )); // create the needed renderer - in this case we use the patTemplate renderer $renderer =& patForms::createRenderer('patTemplate'); // 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.tmpl', // name of the template, to which the elements will // be added. If you ommit this, addGlobalVar() will be used // instead of addVar() 'tmplName' => 'form', // 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(); ?>