Zend_Form_Decorator_Fieldset for individual elements

Photo by no one cares on Unsplash.

If you want to include a <fieldset> in your Zend_Form, you might try the Zend_Form_Decorator_Fieldset decorator. But it's not apparent that this decorator is meant for the form and not the individual elements in it. Instead, here's a custom decorator to render your Zend_Form_Element with a <fieldset>.

class My_Form_Decorator_Fieldset_Element extends Zend_Form_Decorator_Fieldset
     * Attribs that should be removed prior to rendering
     * @var array
    public $stripAttribs = array(

    // Uncomment for Zend Framework versions < 1.12.0.
    /* public function getOptions()
        $options = parent::getOptions();

        // Do not inherit the id of the element.  Ids must be unique.
        // See http://framework.zend.com/issues/browse/ZF-10803.
        if(array_key_exists('id', $options) &&
           $options['id'] == $this->getElement()->getId()) {

        return $options;
    } */

I use this decorator to implement the form design at http://pea.rs/forms/top-labels.



Hi! I'm Drew, the Wimpy Programmer. I'm a software developer and formerly a Windows server administrator. I use this blog to share my mistakes and ideas.