-- Jaka Jančar <[EMAIL PROTECTED]> wrote
(on Sunday, 10 August 2008, 12:13 AM +0200):
> Can someone explain to me why there is even such a flag as allowEmpty in 
> Zend_Form_Element?

First off, this flag has nothing to do with the rest of your post here.
allowEmpty is a flag used when marking an element as required and
allowing auto-insertion of the NotEmpty validator. The value is passed
as the second argument to the NotEmpty validator -- the
'breakChainOnFailure' flag. This flag is used to indicate whether or not
to process _additional_ validators if the current validator fails. So,
basically, it's simply to indicate whether you want to run the complete
validator chain on empty, required values, or only run the NotEmpty
validator.

If you add your own NotEmpty validator as part of the validation chain,
the flag is ignored.

> This to me seems like a job for a validator, and there is no reason that 
> I can see why empty values should be treated differently (skipping 
> validators, auto-adding of validators(NonEmpty), etc.) than any other 
> values.

As noted, this is simply intended to act as a flag to the auto-added
NotEmpty validator. It's not about treating the value differently.

> I've created custom Date, Time and DateTime elements, and used something 
> like this in them:
>
>     public function init()
>     {
>         $this->addValidator('Date', false, array('yyyy-MM-dd  
> HH:mm:ss'));
>     }
>
> Naturally, I would expect that I would either:
>  a) get a valid date OR
>  b) get NULL (if the element wasn't required).
>
> But no. "" also sneaks through, even though it clearly wouldn't pass the 
> validators, if they ran (but they don't).

In this particular case, the element is not marked as required, so when
an empty string is provided (which is what forms submit when no value is
provided), no validations are performed -- hence you receive the empty
string as a value.

> So perhaps I should also check if there are any other special values,  
> like "Hello!", that would entirely bypass the validation, and call  
> setAllowHello(false) and setAllowILoveZendFramework(false) (just making 
> my point :P)
>
> Is it legacy problem, or am I missing something?

Flawed logic on your part;  your understanding of the allowEmpty flag is
incorrect, as outlined above. 

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to