问题
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