Adding values from a checkbox group in formbuilder

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
blackrain
Forum Members
Forum Members
Posts: 98
Joined: Wed Feb 20, 2008 4:33 pm

Adding values from a checkbox group in formbuilder

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Adding values from a checkbox group in formbuilder

Post 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)}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 169
Joined: Fri Feb 06, 2009 2:08 pm

Re: Adding values from a checkbox group in formbuilder

Post 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}
Locked

Return to “Modules/Add-Ons”