Form with Multi Value Checkboxes

5 posts by 2 authors in: Forums > CMS Builder
Last Post: June 25, 2011   (RSS)

By maja13 - June 23, 2011

I built a form in CMS Builder and one of the fields has 6 possible boxes that can be checked. I need them to be able to check more than one box and it display in the record. The user can check more than one box but only the last box they check shows up in the record. What am I missing. Attaching the php file.
Attachments:

intensifyform_muncie.php 30K

Re: [maja13] Form with Multi Value Checkboxes

By Jason - June 23, 2011

Hi,

What's happening is because all of your checkboxes have the same name, they are overriding the previous boxes values in the $_REQUEST array. You can get around this by adding square brackets ([]) to the end of the check box field name like this:

<input type="checkbox" select multiple="multiple" name="adults[]" ...

This will make form return an array for $_REQUEST['adults'], with each element of the array being a value that was checked.

This means that you will then have to take that array and turn it into a tab (\t) separated string like this:

$adults = "";
foreach ($_REQUEST['adults'] as $adultValue) {
$adults .= "\t".mysql_escape($adultValue)."\t";
}


You will then be able to put it into your SQL query like this:

adults = '$adults',

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Form with Multi Value Checkboxes

By maja13 - June 23, 2011

Ok, I thought I had it but I keep getting an error that says line 40.

Re: [maja13] Form with Multi Value Checkboxes

By Jason - June 24, 2011

Hi,

The code I gave you needs to take place after the form has been submitted, but just before you write your INSERT statement.

Try the file attached.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/