Troy L. Marker schrieb:
My suggestion is to change how the validation receives it values. For
instance, you have an array as follows:

$aData = ('username' => 'someone', 'password' => 'somepass');

You could pass this array to Zend_Validata as follows:

$valid = new Zend_Validate($aData);

Now each validator could be changed to accept another parameter indicating
which element of the array the validator would validate. For example:

$valid->addValidator(new Zend_Validate_StringLength(8, 20), true,
'username');

This would validate the 'username' array element.

Hi Troy,

I can't believe it - I actually needed a component like this, and Zend_Validate somehow slipped completely under my radard. As a result, I spent some time last week while I was on vacation to write a class precisely like this from scratch.

This should teach me once and for all to check all the directories in the latest checkout, including the incubator, whenever I'm searching for components :-/

The approach I used was almost exactly like what you described in your post - except for the parameter order. Thus, I second your request :-)

If noone else has the time to implement this, I'll gladly volunteer (I already have the code anyway, I just have to adapt it to Zend_Validate, which is very similar to my own approach).

The question remains though, how to do it in detail:

1. Use the array approach exclusively, single values can no longer be
   checked

2. Allow both arrays and single values using the same isValid() method

3. Have separate methods for checking either arrays or single values

4. Have a specialized subclass, like Zend_ValidateForm or something,
   that specifically handles arrays from web forms

Personally, I am in favour of door 2.

CU
 Markus

Reply via email to