On Fri, 12 Dec 2008, Piotrek Karas wrote:

> Just looking at the UserInput component for the first time, I completed 
> the tutorial sample code, seems to run fine, but I seem to have found 
> some inconsistencies:
> 
> With definition:
> 
> $definition = array(
>      'firstName' => new ezcInputFormDefinitionElement( 
> ezcInputFormDefinitionElement::REQUIRED, 'string' ),
>      'lastName' => new ezcInputFormDefinitionElement( 
> ezcInputFormDefinitionElement::REQUIRED, 'string' ),
>      'age' => new ezcInputFormDefinitionElement( 
> ezcInputFormDefinitionElement::REQUIRED, 'int', array( 'min_range' => 1, 
> 'max_range' => 99 ), FILTER_FLAG_ALLOW_HEX ),
>      'email' => new ezcInputFormDefinitionElement( 
> ezcInputFormDefinitionElement::REQUIRED, 'validate_email' ),
> );
> 
> If I submit an empty form, "age" and "email" get [invalid] warning, and 
> "first name" and "last name" don't.
> 
> 1) Since first and last name are REQUIRED, why is an empty string 
> interpreted as valid?

REQUIRED means that the form that is sent should contain *a* value, not 
that it can't be empty. (We have a feature request for that at 
&activeItem=2)

After that, the filter (string, int, validate_email) runs over it and 
might invalidate it. This happens for int (as an empty string is 0) and 
for email (because it can not be empty and needs to contain an @ etc).

> 2) When I change REQUIRED to ezcInputFormDefinitionElement::OPTIONAL, 
> nothing seems to change.

Correct, because I suppose in your case, all 4 form elements were 
actually sent.

> So how do I make an e-mail field optional, as in "validate the field 
> if some value provided"? It doesn't seem to have any extra options to 
> control that...

You are right here. REQUIRED and OPTIONAL are not as... inituitive as 
they should be unfortunately.

regards,
Derick
-- 
Components mailing list
Components@lists.ez.no
http://lists.ez.no/mailman/listinfo/components

Reply via email to