Hi Amr,
Zend_Validate_NotEmpty is expected to behave on the same way as the
empty() function. So, there is no need to change this behaviour. And I
could also imagine cases where you allow a '0' to be posted. You should
create an own validator for this (I thought Zend_Form used
Zend_Loader_PluginLoader for this, so it shouldn't be hard to add an own
validator).
Regards,
Pieter kokx
Amr Mostafa schreef:
Hi All,
I'm using NotEmpty validator with the new Zend_Form component, to
validate empty fields. But it didn't work out as expected because it
doesn't consider a '0' (zero string) to be empty.
Use cases:
1. Validating numbers, which could have 0 as perfectly valid input.
2. Validating input of radio options that have one of their items'
value set to 0. Example: array(1 => 'Yes', 0 => 'No'). Or similar
controls like select lists.
I understand that this is due to PHP's empty() but I was also
wondering if it's worth adding a special case for string '0'. Of
course, I'm proposing adding strict type checking only, so the integer
0 would still give a false. But string '0' would give a true. The end
behavior would make more sense IMHO.
Thank you
Best,
- Amr