0

我创建了一个表格,它装饰为表格形式

这是我的装饰代码

$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'
        ));

它工作正常,现在我也想装饰错误消息我要更改我的代码吗?

4

2 回答 2

2

这是一种相当复杂的方法。我也为装饰器添加了类,因此您可以像示例那样设置它们的样式。

// 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.' )
            )
            );
于 2010-02-24T12:39:33.260 回答
2

如果你想在一个地方显示所有错误,你应该从每个元素中删除 Error 装饰器,然后添加 formErrors 装饰器。这是如何删除 Zend Form 错误消息的示例?

$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'
)); 
于 2010-02-25T17:09:50.760 回答