I have a problem with Zend_Form empty validator, it validates and return true even if the form is empty. For exemple if username = ‘ ‘ the validator returns true.
The Form
$this->addElement('text','username',array(
'label' => 'APP_FORM_USERNAME',
'require' => true,
'validators' => array(
array('validator' => 'StringLength', true, 'options' => array(3, 50)),
array('validator' => 'Alpha', true),
array('validator' => 'NotEmpty', true, 'options' => Zend_Validate_NotEmpty::ALL)
),
'filters' => array(
'StringTrim'
))
);
How can i return false if is a string is empty?
Thx.
I’m going to answer even though I think you probably have found an answer since you ased this question a couple of months ago already.
setRequired(true)has actually the same effect than thenotEmptyvalidator. It will add anotEmptyvalidator on top of the validators stack.Your mistake is just a simple syntax error: require should be required.