4

在zend中,

使用装饰器如何将验证消息带到文本框旁边。我目前的装修代码

$elementDecoration = array(
            'ViewHelper',
            'Description',
            'Errors',
            array(array('data'  => 'HtmlTag'), array('tag' => 'td','width'=>'75%', 'class' => 'txt-td-field')),
            array('Label', array('tag' => 'td','width'=>'50%', 'class' => 'txt-td-label', 'placement' => 'prepend')),
            array(array('row'   => 'HtmlTag'), array('tag' => 'tr','valign'=>'top'),'width'=>'102%'),
        );

在此处输入图像描述

4

2 回答 2

0
$fname = $this->createElement('text', 'first_name');
$fname ->setRequired(true)
       ->setAttrib('class','my_class')
       ->addValidator('NotEmpty', true, array('Name is required'));
$fname->setDecorators(array('ViewHelper','Errors'));

这将完成这项工作。

于 2013-04-02T11:34:04.063 回答
0

尝试使用自定义装饰器:

class My_Form_Decorator_TdError extends Zend_Form_Decorator_Errors
{
    public function render($content)
    {
        $errors = parent::render('');
        return $content . "<td>" . $errors . "</td>";
    }
}

然后设置装饰器如下:

       $elementDecoration = array(
        'ViewHelper',
        'Description',
        array(array('data'  => 'HtmlTag'), array('tag' => 'td','width'=>'75%', 'class' => 'txt-td-field')),
        array('Label', array('tag' => 'td','width'=>'50%', 'class' => 'txt-td-label', 'placement' => 'prepend')),
        'TdError',enter code here
        array(array('row'   => 'HtmlTag'), array('tag' => 'tr','valign'=>'top'),'width'=>'102%'),
    );

在表单构造函数中设置自定义装饰器调用的路径

$this->addPrefixPath('My_Form_Decorator', 'My/Form/Decorator', 'decorator');
于 2013-04-02T15:47:14.120 回答