« Return to Thread: Zend_Form

Re: Zend_Form

by weierophinney :: Rate this Message:

Reply to Author | View in Thread

-- SiCo007 <simon@...> wrote
(on Friday, 28 March 2008, 06:03 AM -0700):

> I'm trying to disable and reset the decorators on my form but the following
> does nothing!
>
> If I remove disableLoadDefaultDecorators' => true and the line
> $form->setDecorators(array('FormElements', array('HtmlTag', array('tag' =>
> 'div')), 'Form')); then the form displays as normal (i.e. dd tags). If I add
> disableLoadDefaultDecorators' => true, then as expected, nothing shows at
> all. Therefore I added in the form decorators at the bottom and it displays
> the form as normal again.
>
> $form = new Zend_Form(array('disableLoadDefaultDecorators' => true,
> 'elementDecorators' => array(
>        'ViewHelper',
>        array('Description', array('tag' => 'div', 'class' => 'help')),
>        'Errors',
>        array('Label'),
>        array('HtmlTag', array('tag' => 'div', 'class' => 'field'))
>        
>    )));
>    $form->setDecorators(array('FormElements', array('HtmlTag', array('tag'
> => 'div')), 'Form'));
>
> Is this remotely the right way to replace the default decorators or am I
> better off extending the form class outeright?
>
> How do I pass the decorators I wish to use for the form to the constructor?
> I couldn't see this in the setOptions method.
>
> Your help would be greatly appreciated as I can't believe it is as hard as I
> am finding it!

To set decorators, you pass a 'decorators' array in the options passed
to the constructor. I'm going to reformat your example above and add the
decorators:

    $form = new Zend_Form(array(
        'elementDecorators' => array(
         'ViewHelper',
         array('Description', array('tag' => 'div', 'class' => 'help')),
         'Errors',
         array('Label'),
         array('HtmlTag', array('tag' => 'div', 'class' => 'field'))
        ),
        'decorators' => array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div')),
            'Form',
        ),
    ));

That's all there is to it. There's no reason to add the
'disableLoadDefaultDecorators' option, as if any decorators are provided
during initializaiton, the default decorators will not be loaded.

--
Matthew Weier O'Phinney
PHP Developer            | matthew@...
Zend - The PHP Company   | http://www.zend.com/

 « Return to Thread: Zend_Form