« Return to Thread: Zend_Form

Re: Zend_Form

by Simon Corless :: Rate this Message:

Reply to Author | View in Thread

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).

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.

Simon

 « Return to Thread: Zend_Form