overwrite specific Decorators for all Zend_Form Objects

150 views Asked by At

i am working on styling a project and everybody used Zend_Form and default Elements. This makes it impossible to style submit buttons. Therefore i would like to overwrite the default Zend_Form Decorator for submit buttons, but without changing every line where a Zend_Form is created.

Is that possible? If yes, how?

1

There are 1 answers

3
Aron Rotteveel On BEST ANSWER

You probably want to subclass Zend_Form_Element_Submit and use loadDefaultDecorators() to set the default decorators for your submits:

class My_Form_Element_Submit extends Zend_Form_Element_Submit
{
    public function loadDefaultDecorators()
    {
        // set your default decorators for the submit element       
        $decorators = $this->getDecorators();
        if (empty($decorators)) {
            $this->setDecorators(array(
                'ViewHelper',
                array(
                    array('field' => 'HtmlTag'),
                    array(
                        'tag'   => 'span',
                        'class' => 'some-wrapper-class'
                    ) 
                )
            ));
        }
    }
}

The above decorators would result in HTML code looking something like this, allowing you to easily style your submit button:

<span class="some-wrapper-class"> 
    <input type="submit" name="save" id="save" value="Save">
</span>