I have extended Zend_Form to create my custom form that I will reuse on some pages of my site.
For this form I also created some JavaScript validation based upon jquery.
What I would like to do is add this JavaScript validation for the form in the sub-classed Zend_Form. So every time the form is called the JavaScript gets initiated as well.
In a view script you can use $this->headScript()->appendFile(‘/js/val.js’) and than use echo $this->headScript() in the layout. But headScript() is to my knowledge not possible in Zend_Form.
How can I use headscript in Zend_Form or is their a alternative ‘better’ approach
You can use
inside the form to get a reference to your view (via the view renderer). Use the view to access your view helpers then:
I may add that I actually don’t like this approach as it ties your form to the view, but it’s the easiest and fastest way to do what you try to do.