Page 1 of 1

Adding values from a checkbox group in formbuilder

Posted: Fri Aug 16, 2019 3:30 pm
by blackrain
I am trying to calculate the value of a selection of a checkbox group.

I have 25 check boxes and each box is worth 1 point.

if a user selects 5 of the boxes the result returns is "1,1,1,1,1"

I would like to see the result as 5 but what ever I do it sends out "1" unless the raw variable is displayed, then "1,1,1,1,1" is displayed.

my latest effort is below but still only results in "1"

Code: Select all

{foreach from=$fld_177 item=task name=foo}
   {assign var='sum_all_foreach' value=$sum_all_foreach+$task}
{/foreach}
{assign var='result' value=$smarty.foreach.foo.total}
I have tried {math} and {count} but the results just don't make sense.

please help as I am going mad.

Re: Adding values from a checkbox group in formbuilder

Posted: Fri Aug 16, 2019 5:07 pm
by calguy1000
If the raw variable is a string... then you cannot do 'math' on it until you split it out into an array.

{$tmp=explode(',',$fld_177)}

Re: Adding values from a checkbox group in formbuilder

Posted: Fri Aug 16, 2019 5:46 pm
by PinkElephant
Another option is to use internal modifiers on the raw value...

Code: Select all

{assign temp_text value='1,1,1,1,1'}
{$temp_text|replace:',':''|count_characters}