Пример #1
0
 function index($locator)
 {
     $model = $this->_load()->model('Form');
     if ($model->isValid($this->request)) {
         echo 'DONE<br/><br/><a href="../">Return to Examples</a>';
     } else {
         if (!$model->isSubmitted()) {
             $model->set('field1', 15);
             $model->set('field2', 'init');
             $model->set('field3', 'init');
             $model->set('field4', 'init');
         }
         // create HTML form generator
         $form = new A_Html_Form();
         $form->setModel($model)->setWrapper('A_Html_Div', array('class' => 'fieldclass', 'style' => 'border:1px solid red;'))->select(array('name' => 'field1', 'values' => array(5, 10, 15), 'labels' => array('five', 'ten', 'fifteen'), 'id' => 'field1', 'label' => 'Field 1 (Numbers only in range 1-10)', 'after' => $model->getField('field1')->getErrorMsg(', ')))->text(array('name' => 'field2', 'id' => 'field2', 'label' => 'Field 2 (Must match Field 1)', 'after' => $model->getField('field2')->getErrorMsg(', ')))->text(array('name' => 'field3', 'id' => 'field3', 'label' => 'Field 3 (Letters only min length 5)', 'after' => $model->getField('field3')->getErrorMsg(', ')))->text(array('name' => 'field4', 'id' => 'field4', 'label' => 'Field 4 (Convert letters to uppercase)', 'after' => $model->getField('field4')->getErrorMsg(', ')))->submit('submit', 'Submit');
         echo $form->render();
     }
 }
Пример #2
0
 function index($locator)
 {
     $model = new A_Model_Form();
     // get fieldeter object from controller
     $model->addField($field1 = new A_Model_Form_Field('field1'));
     $field1->addFilter(new A_Filter_Regexp('/[^0-9]/', ''));
     $field1->addRule(new A_Rule_Notnull('field1', 'Please enter Field 1'));
     $field1->addRule(new A_Rule_Range(1, 10, 'field1', 'Field 1 must be 1-10'));
     $field1->setType(array('renderer' => 'A_Html_Form_Select', 'values' => array(5, 10, 15), 'labels' => array('five', 'ten', 'fifteen')));
     $model->addField($field2 = new A_Model_Form_Field('field2'));
     $field2->addFilter(new A_Filter_Regexp('/[^0-9]/', ''));
     $field2->addRule(new A_Rule_Notnull('field2', 'Please enter Field 2'));
     $field2->addRule(new A_Rule_Match('field1', 'field2', 'Field 2 must match Field 1'));
     $field2->setType(array('renderer' => 'A_Html_Form_Text', 'size' => '10'));
     $model->addField($field3 = new A_Model_Form_Field('field3'));
     $field3->addFilter(new A_Filter_Regexp('/[^a-zA-Z]/', ''));
     $field3->addRule(new A_Rule_Length(5, 20, 'field3', 'Field 3 must be 5-20 characters'));
     // create fieldeter object then add it to the controller
     $model->addField($field4 = new A_Model_Form_Field('field4'));
     $field4->addFilter(new A_Filter_Regexp('/[^a-zA-Z]/', ''));
     $field4->addFilter(new A_Filter_ToUpper());
     $field4->addRule(new A_Rule_Notnull('field4', 'Please enter Field 4'));
     $model->excludeRules('field3');
     //$model->run($locator);
     $request = $locator->get('Request');
     if ($model->isValid($request)) {
         echo 'DONE<br/><br/><a href="../">Return to Examples</a>';
     } else {
         if (!$model->isSubmitted()) {
             $model->set('field1', 15);
             $model->set('field2', 'init');
             $model->set('field3', 'init');
             $model->set('field4', 'init');
         }
         //dump($model);
         // create HTML form generator
         $form = new A_Html_Form();
         $form->setModel($model)->setWrapper('A_Html_Div', array('class' => 'fieldclass', 'style' => 'border:1px solid red;'))->select(array('name' => 'field1', 'values' => array(5, 10, 15), 'labels' => array('five', 'ten', 'fifteen'), 'id' => 'field1', 'label' => 'Field 1 (Numbers only in range 1-10)', 'after' => $field1->getErrorMsg(', ')))->text(array('name' => 'field2', 'id' => 'field2', 'label' => 'Field 2 (Must match Field 1)', 'after' => $field2->getErrorMsg(', ')))->text(array('name' => 'field3', 'id' => 'field3', 'label' => 'Field 3 (Letters only min length 5)', 'after' => $field3->getErrorMsg(', ')))->text(array('name' => 'field4', 'id' => 'field4', 'label' => 'Field 4 (Convert letters to uppercase)', 'after' => $field4->getErrorMsg(', ')))->submit('submit', 'Submit');
         echo $form->render();
         #			include 'templates/example_form2.php';
     }
 }
Пример #3
0
 function testHtml_FormNotNull()
 {
     $obj = new A_Html_Form();
     $obj->setAction('bar.php');
     $this->assertEqual($obj->render(array('name' => 'foo'), 'content'), '<form action="bar.php" method="post" name="foo">content</form>');
 }
Пример #4
0
$model = array('username' => 'foo');
$form = new A_Html_Form();
$form->setModel($model);
$form->setWrapper('A_Html_Div', array('class' => 'fieldclass', 'style' => 'border:1px solid red;'));
$form->text('username', 'Enter Username:'******'passwd', 'Enter Password:'******'submit', 'login');
echo $form->render();
$form->reset();
$model = new A_Collection();
$model->set('username', 'bar');
$form->setModel($model);
echo '<br/>Fluent usage:';
echo $form->text(array('name' => 'username', 'label' => 'Enter Username:'******'passwd', 'Enter Password:'******'submit', 'login')->render();
echo '<br/>Static usage';
echo A_Html_Form::render(array('action' => 'foo', 'class' => 'bar'), 'Form inputs go here');
echo '<br/>Fieldset usage:';
$fields1 = new A_Html_Form();
$fields1->text('username', 'Enter Username:'******'passwd', 'Enter Password:'******'email', 'Enter Email:');
$fields2->password('phone', 'Enter Phone:');
$form = new A_Html_Form();
$form->fieldset('set1', $fields1->partial());
$form->fieldset('set2', $fields2->partial());
$form->submit('submit', 'login');
echo $form->render();
echo '
</body>
</html>';