Zend Form Validating of required elements

五迷三道 提交于 2020-01-03 05:56:10

问题



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.


回答1:


It was helpful for me:
->setAllowEmpty(false) instead of ->setRequired()




回答2:


try

setRequired(true)

this is right ;)



来源:https://stackoverflow.com/questions/4594773/zend-form-validating-of-required-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!