1

我使用验证器来测试数据库中是否存在登录并且它可以工作,但是在为 Zend 表单添加装饰器后,验证器错误消息不再显示。

编码:

$this->setName("companyadd");

        $comp = new Zend_Validate_Db_NoRecordExists('company', 'name');
        $comp->setMessage("This company exists!!!!");

        $name = new Zend_Form_Element_Text('name');

        $name->addValidator($comp);
        $name->setAttrib('size', '45');
        $name->setLabel('Company Name')
                ->setAttrib('class', 'companyinputs');
        $submit = new Zend_Form_Element_Submit('submit');
        $this->addElements(array( $name, $submit));

        $this->setElementDecorators(
            array(
                'ViewHelper',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array('Label', array('tag' => 'td', 'class' => 'companylabel')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => 'signuptr'))
        ));
        $submit->setDecorators(
            array(
                'ViewHelper',
                array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
                array(array('emptyrow' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element', 'placement' => 'PREPEND')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
        ));
        $this->setDecorators(
            array(
                'FormElements',
                array('HtmlTag', array('tag' => 'table', 'class' => 'signuptable')),
                'Form'
        ));
4

1 回答 1

3

您忘记向装饰器添加错误。

$this->setDecorators(array(
    // add this line
    'Errors',

    'FormElements',
     array('HtmlTag', array('tag' => 'table', 'class' => 'signuptable')),
     'Form'
));
于 2012-05-20T22:25:55.023 回答