counting checkboxes checked in a calc element

wuschel_lux

Member
Hi all,
actually I have a voting form with more checkbox elements with each 2 options. Now I want to monitor in a calc element the number of overall checked boxes.
My first attempt was to give the value = 1 to each option and run this code in the calc element:

PHP:
$c1 = explode(",",'{...vote_c1_raw}'); $c1 = array_sum($c1);
$c2 = explode(",",'{...vote_c2_raw}'); $c2 = array_sum($c2);
....
$mySum = $c1 + $c2 .....;
It works, but I think it's not so elegant. Is there maybe a better way to do so?
Thanks for your support.
 
just an update if some else would do something similar. I had an issue not with the counting but storing the results!
As both checkboxes had the value "1" even when one was checked both were stared as checked in the DB!
So I changed the value to "V1" and "V2" and changing the code a bit:

PHP:
$search = array('V1', 'V2');

$c1 = explode(",",'{...vote_c1_raw}'); $c1 = str_replace($search, '1', $c1); $c1 = array_sum($c1);
$c2 = explode(",",'{...vote_c2_raw}'); $c2 = str_replace($search, '1', $c2); $c2 = array_sum($c2);
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top