Zend_Form is great for prototyping forms. It takes a lot of the drudge work out, and makes forms easily “reusable”. The decorator system, which is admittedly a little scary for the uninitiated, is actually very powerful. I’m suer that eventually, however, we’ve all reached that point. The point where you spend more time configuring the form to do what you want, then actually doing something with it.
This is especially more important when working with talented designers who know their HTML/CSS, and know exactly what theywant to do with the form. Trying to mangle the form to do what they want in that case is generally a waste of time. It also makes it much harder for the designer to apply his CSS magic. You might look and smile at how beautiful =$this->form?> looks, abstracting away all you hard work. However the designer will likely have to see the generated html to get an understanding of the structure. Want to add a CSS class? Good luck.
Eventually, we discover the ViewScript decorator. Although the code in that viewscript can be a bit complex, we once again have panacea. The designer gets a viewscript with which he can muck around. You get to set one or two decorators and we’re back to =$this->form?> again.
How does the ViewScript decorator work? The workhorse of it involves setting up a partial, and pushing in to the “model” of the partial, the form under the alias “element”. Now, anybody who’s read the Zend Framework performance guide, will have noticed that use of partials is somewhat discouraged. To create a partial, it involves cloning Zend_View, and is somewhat of an unneeded overhead.
So is there an an alternative? It hit me today, that there’s absolutely nothing wrong with just outputting the form in the viewscript it self. Instead of:
In a form ViewScript, just output that directly into your viewscript!
If you want the script to be reusable, just use the render viewhelper, as recommended in the performance guide.