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
}
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.
On Tue, Jan 20, 2009 at 21:09, fab2008 <[email protected]> wrote:
>
> I haven't found any solution to my problem yet, anyone can help me?
>
> Thank you very much..
>
>
> fab2008 wrote:
>>
>> Hi all,
>>
>> I've the following situation: In a form i put a multicheckbox element with
>> a certain number of elements say n. I'want the user select a number of
>> elements between x and y with 0 <= x < y <= n
>>
>> For this i've just tried to write my custom validator extending the
>> Zend_Validate_Between class, overriding its isValid method with something
>> similar to this:
>>
>> public function isValid($value) {
>> return parent::isValid(count($value));
>> }
>>
>> because I tought that $value is an array, but it's not the case, my
>> validator will be called once per selected checkbox with scalar values. So
>> I've tried a different approach:
>>
>> protected $count = 0;
>>
>> public function isValid($value) {
>> if (++$this->count > $this->_max) {
>> return false;
>> }
>> return true;
>> }
>>
>> I'm unsure about correctness, it breaks if the same validator instance
>> will be attached to more than one multi element, and clearly it works only
>> for the max, but not for the min.
>>
>> Any suggestion?
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Writing-a-validator-for-limit-the-number-of-selectable-elements-tp21511756p21569555.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>