Because your element is not required, and allows empty values. So what you
need to do is either:
1. ->setRequired(true); or
2. ->setAllowEmpty(false);
Cheers,
- Amr
On Mon, Jun 16, 2008 at 9:43 PM, Mads Lee Jensen <[EMAIL PROTECTED]> wrote:
>
> Hi i been fooling around with some zend_forms
> and i started to customize my error messages for my form-element
> validators.
> i started out using the setRequired(true) to ensure that the value isnt
> empty. but when i later wanted to change the error message i tried
> instantiating a zend_validate_notempty(), change the error message IS_EMPTY
> and addValidator() it to my element.
>
> But it doesnt seem to validate it at all ? isnt it possible to add a
> NotEmpty validator to an element ? or what am i doing wrong..
>
> heres a test i wrote.
>
> $form = new Zend_Form;
> $form->setAction('/admin/auth/index/');
> $form->setMethod('post');
>
> $validatorNotEmpty = new Zend_Validate_NotEmpty();
> $validatorNotEmpty->setMessages(
> array(
> Zend_Validate_NotEmpty::IS_EMPTY => 'Value is empty'
> )
> );
>
> $myTest = $form->createElement('text', 'myTest');
> $myTest->addValidator($validatorNotEmpty);
>
> $form->addElement($myTest);
> $form->addElement('submit', 'submit');
>
> if ($this->getRequest()->isPost())
> {
> $form->isValid($_POST);
> }
> echo $form;
> --
> View this message in context:
> http://www.nabble.com/Zend_Form_Element-validating-NotEmpty-not-working-tp17870897p17870897.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>
--
Amr Mostafa
Head of Software Development, IT Synergy
[EMAIL PROTECTED] http://itsyn.com
+(2012)1700502 +(202)35371020