Jan 19 2011

Using Zend_Form_Decorators to compose a form as table rows

Ahh Zend form decorators, they certainly have a reputation of being quite difficult to pick up. I suffered similar problems but persevered to get the table layout I wanted.

$form->setElementDecorators(array(
    'ViewHelper',
    array('Description', array('tag' => 'span')),
    array('Errors'),
    array('HtmlTag', array('tag' => 'td')),
    array('Label', array('tag' => 'th', 'requiredSuffix' => ' *')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
));

The above code will result in the following (albeit not quite as neatly):

<tr>
    <th>Label *</th>
    <td>
        <input type="text" /><span class="hint">Description</span>
        <ul class="errors"><li>Error</li></ul>
    </td>
</tr>

For reference example was written with Zend Framework 1.11.2.

comments powered by Disqus

Info

I'm Ade Slade, a PHP web developer.