SHOW:
|
|
- or go back to the newest paste.
| 1 | //getting the form | |
| 2 | $name = new Element('name');
| |
| 3 | $name->setAttributes(array('type' => 'text', 'label' => 'Your name'));
| |
| 4 | $form = new Form('contact');
| |
| 5 | $form->add($name); | |
| 6 | ||
| 7 | // than I return the form to view | |
| 8 | public function indexAction () | |
| 9 | {
| |
| 10 | return new ViewModel(array('form' => $this->getForm()));
| |
| 11 | } | |
| 12 | ||
| 13 | //in view | |
| 14 | <?php | |
| 15 | // within a view script | |
| 16 | $form = $this->form; | |
| 17 | $form->prepare(); | |
| 18 | // Assuming the "contact/process" route exists... | |
| 19 | $form->setAttribute('action', 'contact/process');
| |
| 20 | // Set the method attribute for the form | |
| 21 | $form->setAttribute('method', 'post');
| |
| 22 | // Render the opening tag | |
| 23 | echo $this->form()->openTag($form); | |
| 24 | ?> | |
| 25 | <div class="form_element"> | |
| 26 | <?php | |
| 27 | $name = $form->get('name');
| |
| 28 | echo $this->formLabel()->openTag($name); | |
| 29 | echo $this->formInput($name); | |
| 30 | echo $this->formElementErrors($name); | |
| 31 | echo $this->formLabel()->closeTag(); | |
| 32 | ?></div> | |
| 33 | ||
| 34 | - | // i expect the "formLabel" to echo the label. It does. But the label is empty - the "Your name" is missing. |
| 34 | + | // i expect the "formLabel" to echo the label. It does. But the label is empty - the "Your name" is missing. |
| 35 | ||
| 36 | //SOLVED - I need to echo the label myself: | |
| 37 | echo $this->escape($name->getAttribute('label'));
| |
| 38 | ||
| 39 | // FFffffffffuuuuuuuuu |