Zend Framework: help needed with Form Decorators

274 Views Asked by At

I'm new with developing in Zend Framework. I did some research about form decorators but i want some specific stuff.

This is what i want:

<table>
<tr>
    <td colspan="2">
        <ul class="errors">
            <li>error</li>
        </ul>
     </td>
</tr>
<tr>
   <td>Label :</td>
   <td>input field</td>
</tr>
<tr>
   <td></td>
   <td>Submit Button</td>
</tr>
</table>

What i've got is:

   $this->setElementDecorators(array(
        'ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
        array('Label', array('tag' => 'td')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));

    $submit->setDecorators(array('ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
        array(array('emptyrow' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element', 'placement' => 'PREPEND')),
        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
    ));

    $this->setDecorators(array(
        'FormElements',
        'Errors'
        array('HtmlTag', array('tag' => 'table')),
        'Form'
    ));

but it comes with an htmlspecialchar warning, and the ul is empty.

is there any possibility to fix this?

1

There are 1 best solutions below

0
On BEST ANSWER

Validation errors are tied to individual inputs rather than to the form, so I believe you may have a hard time getting this to work using decorators only.

I would simply render the individual form elements, along with the validation errors, separately in the view script. You'd need to prepare the errors for display yourself and get rid of the decorators altogether, sticking only with the ViewHelper. Then you can do this:

<form method="post">
  <table>
  <tr>
    <td colspan="2"><?php echo $this->errors; ?></td>
  </tr>
  <tr>
    <td><?php echo $this->form->foo->getLabel(); ?></td>
    <td><?php echo $this->form->foo; ?></dt>
  </tr>
  </table>
</form>