I ran into a similar problem where I had written a validator that
takes an array input. There was no way to use it as the logic
structure below must return valid/invalid for each element so the
single elements weren't valid in my validator even thought the array
as a whole was valid. It would be nice if we could some how apply
validators to the individual elements of the array as well as the
array as a whole.
- Jeff
On 25-Apr-08, at 7:24 AM, Xavier Vidal Piera wrote:
Hi
I've write a validator called "ADM_Validate_ArrayCount" that acts
like StringLength but with arrays. I want to know if a "select
multiple" from a form has 1,2,..N selected elements.
Looking at the Zend_Form_Element source code I see the isValid
method and it's doing something i cannot understand why.
This is the piece of code:
foreach ($this->getValidators() as $key => $validator) {
if (method_exists($validator, 'setTranslator')) {
$validator->setTranslator($translator);
}
if ($isArray && is_array($value)) {
$messages = array();
$errors = array();
foreach ($value as $val) {
if (!$validator->isValid($val, $context)) {
$result = false;
$messages = array_merge($messages,
$validator->getMessages());
$errors = array_merge($errors,
$validator->getErrors());
}
}
if ($result) {
continue;
}
}
If the received value is an array, why is forcing me to validate
each element? maybe we need some flag to define if we want to
validate the whole array at once or each element with the validator.
Of course, I can extend Zend_Form_Element and override the "isValid"
method but I want to know how you're validating multiple selects
(apart from notEmpty validators...).
Thanks !
--
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://web.xaviervidal.net
610.68.41.78