简体   繁体   中英

Zend Form Validating of required elements


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.

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

try

setRequired(true)

this is right ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM