There are times when the ordinary decorators just is not enough for your forms. I had one project where we used clickable images to affect the contents of our form element. These images needed to be embedded into the form. Doing this with decorators turned out to be complicated so we used custom view scripts instead. It gave much more readable code.
Here is a small example in Zend Framework 1.10
First we need a form (application/forms/Login.php):
class Application_Form_Login extends Zend_Form { public function init() { $this->setName('login'); $email = new Zend_Form_Element_Text('email'); $email->addValidator('EmailAddress') ->setRequired(true) ->addFilter('StripTags') ->addFilter('StringTrim'); $pass = new Zend_Form_Element_Password('pass'); $pass ->setRequired(true) ->addFilter('StripTags') ->addFilter('StringTrim'); $submit = new Zend_Form_Element_Submit('login'); $submit->setLabel('Login'); $this->addElements(array($email, $pass, $submit)); } }
Then we create the view script (application/views/scripts/index/loginForm.phtml):
0 Comments.