Saturday, March 12, 2011

Removing dl, dt and dd default decorators in Zend_Form

If you are having problems with Zend_Form default document list tags dl, dt and dd tags just remove them and place the list tags.

Follow the following coding method:

$this->clearDecorators();
        $this->addDecorator('FormElements')
         ->addDecorator('HtmlTag', 
                           array('tag' => '<ul>'))
         ->addDecorator('Form');
        
        $this->setElementDecorators(array(
            array('ViewHelper'),
            array('Errors'),
            array('Description'),
            array('Label', array('separator'=>' ')),
            array('HtmlTag', 
            array('tag' => 'li', 'class'=>'form_elements')),
        ));

        $submit->setDecorators(array(
            array('ViewHelper'),
            array('Description'),
            array('HtmlTag', 
            array('tag' => 'li', 'class'=>'submit_button')),
        ));

Here, first we clear the default decorators. Then using setElementDecorators method we add our custom form decorators.

As we do not require label tag and display of errors for the submit button we separately add the decorators for submit button using the method setDecorators.