Is there any real difference between the behavior or output of these 2. They look to me like they do the same thing.
->addValidator('NotEmpty')
->setRequired(true)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, there’s a difference. If an element is not required, it’ll validate even if the whole value is missing from the data you validate against. The value is only validated against registered validators after it’s been determined that it exists.
NotEmptyvalidator will only fail if the field is present, but is empty.Also, it’s not necessary to add NotEmpty validator yourself, by default Zend auto inserts NotEmpty validator for elements, if the element is required. So effectively doing
->setRequired(true)is same as doing->setRequired(true)->addValidator('NotEmpty'). You can turn off this behavior with->setAutoInsertNotEmptyValidator(false).