Now i'm creating a custom MultiSelect Form Element (extending
Zend_Form_Element_MultiSelect) so I can override the "isValid" function to
achieve the validation of the whole array instead of his elements.

The problem now is to make a safe code to allow "single-element validators"
and "array validators" to be added to the element without getting conflicts.

If I succeed, i will post the code here.

On Fri, Apr 25, 2008 at 1:45 PM, Jeffrey Sambells <[EMAIL PROTECTED]>
wrote:

> 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
>
>
>


-- 
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

Reply via email to