views:

433

answers:

2

hello

i created a form that it decorates as table form

its my code for decorates

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

    ));

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

it works correctly, now i wana errors message decorates too what do i change my code?

A: 

Here is a rather complex way of doing it. I have added classes to the decorators too so you can style them unlike your example.

// To be assigned at the beginning of your form class.

    public $elementDecorators = array(
    'ViewHelper',
    'Errors',
    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'col2')),
    array('Label', array('tag' => 'td','class'=>'taR')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr','class' => 'rowA')),
    );

$this->addElement('ValidationTextBox', 'name', array(
            'decorators' => $this->elementDecorators,
            'validators' => array(                                 
                                array('regex',  false,'/^[a-zA-Z ]+$/')
                            ),
            'label' => $this->translator->translate ( 'Name' ) . ' : ',
            'required' => true,
            'trim' => true,
            'propercase' => true,
             'regExp' => '[a-zA-Z ]+',
                'invalidMessage' => $this->translator->translate ( 'Name - Must be alpha numeric.' )
            )
            );
Laykes
i want error message is displayed beside elements not under them, how can i decorates them
ulduz114
A: 

If you want to show all erros grouped in one place you should remove the Error decorator from each element and then add to you form the formErrors decorator. Here is an example from http://stackoverflow.com/questions/2065903/how-to-remove-zend-form-error-messages

$form->setDecorators(array(
    'FormElements',
    new Zend_Form_Decorator_FormErrors(array
        (
            'ignoreSubForms' => true,
            'markupElementLabelEnd' => '</b>',
            'markupElementLabelStart' => '<b>',
            'markupListEnd' => '</div>',
            'markupListItemEnd' => '</span>',
            'markupListItemStart' => '<span>',
            'markupListStart' => '<div id="Form_Errors">'
        )
    ),
    'Form'
)); 
Keyne