/** * Create password element. * * @param string $alias element alias * @param string $label element label */ function __construct($alias, $label) { parent::__construct($alias, $label); // by default, should not redisplay any values $this->redisplayInvalid(false); $this->redisplayValid(false); }
/** * Create address input. * * @param string $alias alias * @param string $label label * @param T_Factory address factory */ function __construct($alias, $label, T_Factory $factory) { parent::__construct($alias, $label); $this->factory = $factory; $line_1 = new T_Form_Text($alias . '_line_1', 'Line #1'); $line_1->setAttribute('maxlength', 200)->setAttribute('size', 30); $this->addChild($line_1); $line_2 = new T_Form_Text($alias . '_line_2', 'Line #2'); $line_2->setAttribute('maxlength', 200)->setAttribute('size', 30)->setOptional(); $this->addChild($line_2); $city = new T_Form_Text($alias . '_city', 'Town/City'); $city->setAttribute('maxlength', 200)->setAttribute('size', 30); $this->addChild($city); $region = new T_Form_Text($alias . '_state', 'County/State'); $region->setAttribute('maxlength', 200)->setAttribute('size', 30)->setOptional(); $this->addChild($region); $postcode = new T_Form_Text($alias . '_postcode', 'Postcode'); $postcode->setAttribute('maxlength', 20)->setAttribute('size', 10)->setOptional(); $this->addChild($postcode); }
<?php // CREATE FORM $form = new T_Form_Post('cv', 'Create CV'); $fieldset = new T_Form_Fieldset('details', 'Your Details'); $form->addChild($fieldset); $fieldset->addChild(new T_Form_Text('name', 'Name')); $email = new T_Form_Text('email', 'Email'); $email->attachFilter(new T_Validate_Email()); $fieldset->addChild($email); $fieldset = new T_Form_Fieldset('prev_jobs', 'Your Previous Jobs'); $form->addChild($fieldset); $repeated = new T_Form_Repeated('jobs', 'Add Another Job', 1, 6); $repeated->addChild(new T_Form_Text('title', 'Title')); $repeated->addChild(new T_Form_Text('company', 'Company')); $start = new T_Form_Text('start', 'Start Date'); $start->setHelp('Enter date in format dd/mm/yyyy'); $start->setOptional()->attachFilter(new T_Validate_UnixDate('d|m|y')); $repeated->addChild($start); $fieldset->addChild($repeated); $skills = new T_Form_TextArea('skills', 'Additional Info'); $skills->setOptional()->setHelp('Describe any additional career achievements, etc.'); $fieldset->addChild($skills); $form->setForward($env->getRequestUrl()); // VALIDATE FORM if ($env->isMethod('POST')) { $form->validate($env->input('POST')); } // ACTION FORM if ($form->isPresent() && $form->isValid()) { $f = new T_Filter_Xhtml();
<?php define('DEMO', 'Multistep Form'); require dirname(__FILE__) . '/inc/header.php'; // CREATE FORM $form = new T_Form_MultiStep('insurance', 'Get a Quote'); // step 1 $step1 = new T_Form_Step('you', 'Contact Details'); $form->addChild($step1); $fieldset = new T_Form_Fieldset('contact_details', 'Your Details'); $step1->addChild($fieldset); $fieldset->addChild(new T_Form_Text('name', 'Name')); $email = new T_Form_Text('email', 'Email'); $email->attachFilter(new T_Validate_Email()); $fieldset->addChild($email); // step 2 $step2 = new T_Form_Step('your_history', 'Your History'); $form->addChild($step2); $fieldset = new T_Form_Fieldset('driver_history', 'Driver History'); $step2->addChild($fieldset); $comment = new T_Form_TextArea('penalty', 'Details of any driving penalties:'); $comment->setOptional(); $fieldset->addChild($comment); // step 3 $step3 = new T_Form_Step('car', 'Your Car'); $form->addChild($step3); $fieldset = new T_Form_Fieldset('car_details', 'Your Car'); $step3->addChild($fieldset); $fieldset->addChild(new T_Form_Text('reg', 'Registration')); $fieldset->addChild(new T_Form_Text('make', 'Make')); $fieldset->addChild(new T_Form_Text('model', 'Model'));
/** * Visit a text input node. * * @param T_Form_Input $node */ function visitFormText(T_Form_Text $node) { $attributes = $node->getAllAttributes(); $attributes += array('type' => 'text', 'name' => $node->getFieldname(), 'id' => $this->getNodeId($node), 'value' => $node->getDefault()); $xhtml = $this->createLabel($node) . $this->createInput($node, $attributes); $this->addXhtml($xhtml); }