如何解决Zend形式:不会显示错误
| Zend talk。我在Web应用程序中构建了一个自定义的Zend_form。问题是我无法显示错误(当我提交不带任何文本的表单时)。我缺少明显的东西吗?class Commentform extends Zend_Form
{
public function init()
{
$this->setMethod(\'post\');
$this->setAction(\'\');
$text=new Zend_Form_Element_Textarea(\'text\');
$text->setRequired(true)
->addFilter(\'StringTrim\')
->addFilter(\'StripTags\')
->setDescription(\'bla bla\');
$submit=new Zend_Form_Element_Submit(\'commenta\');
$this->addElements(array($text,$submit));
$this->setElementDecorators(array(
\'ViewHelper\',array(\'Description\',array(
\'tag\'=>\'span\',\'class\'=>\'medium\',\'placement\'=>\'PREPEND\')),));
$this->setDecorators(array(
\'FormElements\',\'FormErrors\',\'Form\',array(\'tag\'=>\'h2\',\'placement\'=>\'prepend\')),array(\'HtmlTag\',array(\'tag\' => \'div\',\'class\'=>\'write_comment\')),));
$this->setDescription(\'zend zend\');
}
}
谢谢
路卡
解决方法
在表单上使用的正确装饰器是FormErrors,例如
$this->setDecorators(array(
\'FormElements\',\'FormErrors\',\'Form\',array(\'Description\',array(\'tag\'=>\'h2\',\'placement\'=>\'prepend\')),array(\'HtmlTag\',array(\'tag\' => \'div\',\'class\'=>\'write_comment\')),));
错误装饰器用于元素。
, 您必须在表单元素中放置一个\“ Errors \”装饰器。 Zend_Form_Element默认情况下会加载此\“ Errors \”装饰器,如您在Zend_Form_Element源代码中所见:
public function loadDefaultDecorators()
{
...
$this->addDecorator(\'ViewHelper\')
->addDecorator(\'Errors\')
->addDecorator(\'Description\',array(\'tag\' => \'p\',\'class\' => \'description\'))
->addDecorator(\'HtmlTag\',array(\'tag\' => \'dd\',\'id\' => array(\'callback\' => $getId)))
->addDecorator(\'Label\',array(\'tag\' => \'dt\'));
...
}
因为要覆盖此行为而没有提供\“ Errors \”装饰器,所以不会显示元素级错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。