Benjamin Mukasa
Benjamin Mukasa

Reputation: 23

Zend Framework Form Decorators for Error Messages

I have been trying to use decorators to format my form. I have formatted the form elements into a table. I have formatted the button elements. I just need to know what options to put into setDecorator to make my error messages appear in a <td> tag or cell next to the respective input field instead of below it.

I have tried putting errors in an array and setting the 'tag' => 'td' but it does not work. Any help would be appreciated.

My code so far is:

public $elementDecorators = array(  
    'ViewHelper',  
    'Errors',  
    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),  
    array('label', array('tag' => 'td')),  
    array(array('row' => 'HtmlTag'), array('tag' => 'tr')),  
);

Upvotes: 2

Views: 4530

Answers (1)

Iscander
Iscander

Reputation: 444

Try this:

    $elementDecorators = array(
        'ViewHelper',
        array(
            array('data' => 'HtmlTag'),
            array('tag' => 'td')
        ),
        array(
            array('openerror' => 'HtmlTag'),
            array('tag' => 'td', 'openOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)
        ),
        'Errors',
        array(
            array('closeerror' => 'HtmlTag'),
            array('tag' => 'td', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)
        ),
        array('Label',
            array('tag' => 'td')
        ),
        array(
            array('row' => 'HtmlTag'),
            array('tag' => 'tr')
        )
    );

Upvotes: 7

Related Questions