Emanuel-20 wrote:
>
> If the name attribute of the input tag would be like: "myChecks[]" for
> all the n checkboxes then the result will come as an array, and u
> could use in your script:
>
> if (!$myValidator->isValid(count($sentArray))) {
> echo "The number of selected checkboxes must be at least x and at most
> y";
> } else {
> //validate the contents of $sentArray and process its values
> }
>
Yes, this solution works well, but it does not integrate in the Zend_Form
well. I'can also put this code in my script:
if (count($_POST['myCheck']) > x || count($_POST['myCheck']) < y) {
echo "Something...";
exit();
}
but this not show errors on form and it breaks the normal flow of my app.
What I love of Zend_Form component (using validators and filters) is the
oppurtunity to show error messages below the wrong value, and the
opportunity to made all the constraint checks with a single instruction in
the controller like this one:
if ($form->isValid($_POST)) {
// here I can access valid and filtered values
// without any additional check
}
If I using the above approach, I can not do this anymore.
Emanuel-20 wrote:
>
> P.S. Don't write the custom validator unless the functionalities
> provided cannot be achieved using the existing ones, because the
> memory is still a limited resource nowadays and you might need it
> somewhere else.
>
Yes, the memory is a problem with PHP, but I think that most of memory is
used by MVC architecture; the validators use only a minimum part of it. Like
everything is a matter of compromise between performance/memory usage/cpu
usage and code simplicity, readability and mantainability; I prefer the
second ones (within certain limits), because they are more important than
the other ones, otherwise we should keep program with assembler, because is
the more performant language.
--
View this message in context:
http://www.nabble.com/Writing-a-validator-for-limit-the-number-of-selectable-elements-tp21511756p21585588.html
Sent from the Zend Framework mailing list archive at Nabble.com.