Zend Form验证所需元素 [英] Zend Form Validating of required elements
本文介绍了Zend Form验证所需元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在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));
所有验证器都可以正常工作.但这是一个问题.在控制器中,我使用 getValidValues 检查表单(这对我来说是必需的).并且,如果存在DB中的Record记录,则该元素无效,并且Zend清除了此元素.我接受要求值"的信息.我如何获取有关DB中行存在的消息?
抱歉,我的英语.预先谢谢你.
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.
推荐答案
对我很有帮助:
->setAllowEmpty(false)
而不是->setRequired()
It was helpful for me:->setAllowEmpty(false)
instead of ->setRequired()
这篇关于Zend Form验证所需元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文