[SOLVED] CHECKBOX ELEMENT: HOW TO LIMIT CHECKED QUANTITY

kaito

Member
Hi to everybody:

For a checkbox element I want to set a maximum value for checked items.

I looked for in the forum and found this post: https://fabrikar.com/forums/index.php?threads/howto-limit-the-number-of-selections-for-checkbox-element.20557/
using a PHP validation based in counting separator character of the values stored in the element value, I set PHP validation for a maximum of 3 items checked, so there will be a maximum of 3-1=2 separator characters:

PHP:
If ("substr_count({afab_votacioncursotipo01___comocalificariasalponente_raw}","-") > 2)
   {
   return false;
   }
else {
   return true;
   }

I have tried with different separator characters as "-" or "," with no efect, when I try to run the form, there is a validating icon appearing with no end.

Is there any way to know the syntax about how checkbox element stores temporally checked values? If I know it, then I can look for that separator caharacter using substr_count function.

Or is there any other way to set a maximum value for checked options?

Thanks in advance,

kaito
 
The post you're referring to is soon 10 years old.

Instead, in the "PHP code" field of the PHP validation plugin, enter this:
Code:
return count($formModel->formData['afab_votacioncursotipo01___comocalificariasalponente']) <= 3;
 
Joomla 4.3.2, FabriK Gamma 3, PHP 8.1
Reports the following error:
count(): Argument #1 ($value) must be of type Countable|array, null given
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top