ZF-4811: Zend_Form_Element->addValidator() should allow multiple instances of the same validator


As mentioned in the subject I believe this would be very useful, e.g. when using advanced validation through custom validators. In my case (to giva a concrete example) there is a validator called exTSend_Validate_FunctionReturnsTrue. When instantiating it one passes in a function that gets passed the value to validate and, if specified, other parameters, and has to return TRUE when the value is valid. As there may be the case that you want to validate one value with multiple functions there's currently no way to do it as addValidator() overwrites all previous passed instances as they match in the name (derived from the validator class name).

My suggestion would be to add a getName() and setName() method to each validator (ok, to the Abstract would be better) so one can specify the name if (s)he wants, by default this could still be the class name. As far as I can see there should be no side-effects but a big gain in usability, especially when one develops heavy custom validations that can't be done within a single validator or need to be "semi-generic".


There's already more than enough complexity in Zend_Form without this. I would suggest that this sort of thing should be done with a composite validator -- a validator that consumes one or more other validators.This would push the complexity into the validators and not Zend_Form, which is what I argue is a better practice in this case.