Chris Hartjes’ Blog: Creating Usable Forms With Zend Framework

In his recent post Chris Hartjes looks into creating forms in Zend Framework in a little bit more reusable way.

After searching around online for some examples of building simple forms, I was dismayed to discover there were two different ways of building the form. I could (a) do it the long way and create specific instances of the form elements using Zend_Form_Element_X or (b) do it the short way and add them to the form by use of Zend_Form::addElement() and pass it the type of form element I want via an array. For reasons I cannot explain initially, I decided to do things the long way. Later on, I found out that doing it this way saved me from rewriting.

He shows how to separate form from controller, reuse the same form in “add” and “edit” actions and use decorators to change the way form renders.