Zend Form 验证所需元素
我的 Zend Form 中有所需的元素:
$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name')
->setValue(isset($plan)?$plan['name']:'')
->setRequired()
->setAttribs(array('class' => 'required', 'maxlength' => 50))
->addValidators(array(new Zend_Validate_StringLength(array('min' => 1, 'max' => 50)),
new Zend_Validate_Db_NoRecordExists(array('table' => 'plan', 'field' => 'name')))
->addFilters(array(new Zend_Filter_StringTrim, new Zend_Filter_StripTags));
所有验证器都工作完美。但这是一个问题。在控制器中,我使用 getValidValues 检查表单(这对我来说是必需的)。如果数据库中的记录存在,则元素无效,Zend 清除该元素。我接受了“需要价值”的信息。如何获取有关数据库中现有行的消息?
抱歉我的英语。先感谢您。
I have the required element in my Zend Form:
$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name')
->setValue(isset($plan)?$plan['name']:'')
->setRequired()
->setAttribs(array('class' => 'required', 'maxlength' => 50))
->addValidators(array(new Zend_Validate_StringLength(array('min' => 1, 'max' => 50)),
new Zend_Validate_Db_NoRecordExists(array('table' => 'plan', 'field' => 'name')))
->addFilters(array(new Zend_Filter_StringTrim, new Zend_Filter_StripTags));
All validators work perfect. But it is one problem. In controller I check form using getValidValues (it is required for me). And if Record in DB is exist, element is invalid and Zend clear this element. And I take the message 'Value is required'. How can I get message about existing of row in DB?
Sorry for my english. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我很有帮助:
->setAllowEmpty(false)
而不是->setRequired()
It was helpful for me:
->setAllowEmpty(false)
instead of->setRequired()
尝试
setRequired(true)
这是正确的;)
try
setRequired(true)
this is right ;)