views:

34

answers:

1

I need to output the following form layout:

<tr><td>Label</td><td>Element</td></tr>
<tr><td></td><td>ElementErrors</td></tr>

This is needed for the elements and labels to be centered vertically and errors should be with the same indentation as elements.

Can I achieve this with the usage of decorators or maybe I need to change my markup?

A: 

You would use decorators. For the simplest example of a custom decorator, check out Matthew's tutorial here, specifically the My_Decorator_SimpleInput decorator.

so you could do something along the lines of

class My_Decorator_SimpleInput extends Zend_Form_Decorator_Abstract
{
    protected $_format = '<tr><td><label for="%s">%s</label></td><td><input id="%s" name="%s" type="text" value="%s"/></td></tr>';

    public function render($content)
    {
        $element = $this->getElement();
        $name    = htmlentities($element->getFullyQualifiedName());
        $label   = htmlentities($element->getLabel());
        $id      = htmlentities($element->getId());
        $value   = htmlentities($element->getValue());

        $markup  = sprintf($this->_format, $id, $label, $id, $name, $value);
        return $markup;
    }
}
Mark