-- SiCo007 <[EMAIL PROTECTED]> wrote
(on Friday, 28 March 2008, 10:38 AM -0700):
> 
> 
> Matthew Weier O'Phinney-3 wrote:
> >  
> >     $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',
> >         ),
> >     ));
> 
> Hmm ok I have copied that directly into my form and nothing, it's still
> rendering the default code with definition lists. I am stumped, unless I
> have done something obviously daft (ZF 1.5.1).

Okay, I missed something in the previous emails. setElementDecorators()
applies to elements set *before* it is called. When the
'elementDecorators' config option is passed, it is run on all elements
created during configuration -- which you would have to do my passing an
'elements' option to the configuration, with all element configurations.
It can be done, but it's harder to read and debug.

In the example you have, you create the form, and *then* create your
individual elements. However, setElementDecorators(), as mentioned,
applies to *existing registered* elements, not ones added after it is
called.

I'd recommend calling setElementDecorators() on your form object *after*
creating all of your elements and registering them with the form object.

The other option is to create your own subclasses of the elements you
use and override their loadDefaultDecorators() methods to set your own
decorators. This would be the most extensible way to do so.


> The HTMl output is:
> <form enctype="application/x-www-form-urlencoded" action=""
> method="post"><div>
> <dt></dt>
> <dd>
> <input type="hidden" name="id" value="0" id="id" /></dd>
> <dt><label for="name" class="required">Name</label></dt>
> <dd>
> <input type="text" name="name" id="name" value=""></dd></div></form>
> 
> And the PHP is as follows:
> 
> $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', 
>         ), 
>     )); 
>               
> $form->addElement('hidden', 'id', array('validators' => array('Int'),
> 'filters' => array('Int')));
>         
> $form->addElement('text', 'name', array('required' => true, 'filters' =>
> array('StringTrim', 'StringToLower'), 'label' => 'Name', 'description' => 'A
> unique name for the action, letters only.'));
> 
> $this->view->form = $form;
> 
> Now am I missing something, or doing something insanely stupid? The form
> creation is copied from your post earlier and the fields etc should be based
> on the docs.
> 
> 
> 
> > Well, no, it can't -- because you don't have any validators associated 
> > with it. You *have* made it required, but because you don't explicitly 
> > set a NotEmpty validator, there's no way to set the message. 
> > 
> 
> That was an over sight in my code pasting sorry, i wasn't aware you had to
> specifically apply the notEmpty validator in order to set it's message, that
> makes sense though.
> 
> You're probably sick of me by now but I would really like to get this
> working as I can't believe it's really this difficult! Thanks for all your
> help so far.

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to