Zend Form Validating of required elements

2019-06-08 19:47发布


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.

2条回答
Summer. ? 凉城
2楼-- · 2019-06-08 20:26

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

查看更多
▲ chillily
3楼-- · 2019-06-08 20:51

try

setRequired(true)

this is right ;)

查看更多
登录 后发表回答