Jump to content

Checkbox values not sending


hockey05

Recommended Posts

I need help with passing checkboxes values to a php results form and to an email address.  When I test the form and check one of the boxes nothing gets passed.  Any help would be much appreciated!!

 

Here is the checkbox portion of the form:

 

<input type="checkbox" name="Classics" value="Classics"> Classics<br>

<br><input type="checkbox" name="Pops" value="Pops"> Pops<br>

<br><input type="checkbox" name="Symphony" value="Symphony"> Symphony Under the Stars and other outdoor concerts<br>

<br><input type="checkbox" name="Nutcracker" value="Nutcracker"> Nutcracker<br>

<br><input type="checkbox" name="ChamberMusic" value="ChamberMusic"> Chamber music<br>

<br><input type="checkbox" name="ChamberOrch" value="ChamberOrch"> Chamber orchestra<br>

<br><input type="checkbox" name="Film" value="Film"> Film music and other pop culture-related programs<br>

 

 

Here is the checkbox results portion:

 

tr_row("What types of concerts are you interested in?", "nbsp"]);

$htmlmsg .= "<tr>";

if ($Classics != "") $htmlmsg .= $Classics."<BR>";

if ($Pops != "") $htmlmsg .= $Pops."<BR>";

if ($Symphony != "") $htmlmsg .= $Symphony."<BR>";

if ($Nutcracker != "") $htmlmsg .= $Nutcracker."<BR>";

if ($ChamberMusic != "") $htmlmsg .= $ChamberMusic."<BR>";

if ($ChamberOrch != "") $htmlmsg .= $ChamberOrch."<BR>";

if ($Film != "") $htmlmsg .= $Film."<BR>";

 

$htmlmsg .= "</td></tr>";

$htmlmsg .= "</td></tr>";

$htmlmsg .= "</table>";

 

Link to comment
https://forums.phpfreaks.com/topic/111011-checkbox-values-not-sending/
Share on other sites

The checkboxes that you want to have associated with each other all need the same name, as well as empty brackets ( [] ) like this:

 

<input type="checkbox" name="group1[]" value="Pops"> Pops

<input type="checkbox" name="group1[]" value="Classics"> Classics

 

Then PHP will get an array, $_POST['group1'] which will hold all the values that were checked. If no values are checked, then the array will be null.

 

Also, you are assuming the values from the checkboxes are in variables already. If register_globals is off, they will not be accessible through $Pops, but rather through $_POST['checkbox name']['value'], as described above.

 

and actually you're not overwriting the value of $htmlmsg each time.

 

HTH

Dan

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.