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

Issue Type: Improvement Created: 2008-11-05T14:51:41.000+0000 Last Updated: 2010-09-28T02:34:22.000+0000 Status: Resolved Fix version(s): Reporter: Gabriel Schuster (g.schuster) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: - ZF-10497



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


Posted by Matthew Weier O'Phinney (matthew) on 2008-11-05T15:25:40.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.