Jump to content

checkbox group form submission


mark60480

Recommended Posts

I'm trying to include a checkbox group in a form submission. The user can check one, two, or all three of the choices. I need only the checked boxes to appear in the e-mail to the admin. I understand I need to do some kind of an array, but don't know how. Here is the checkbox group code:

 

 

           
            <input type="checkbox" name="CheckboxGroup1[]" value="Choice1" id="1" />Select choice 1
            <input type="checkbox" name="CheckboxGroup1[]" value="Choice2" id="2" />Select choice 2
            <input type="checkbox" name="CheckboxGroup1[]" value="Choice3" id="3" />Select choice 3
 
And here is the line in the script:
 
            $mail_body .= "Choices: ".$_REQUEST['CheckboxGroup1'];
 
I will also attach the entire script.
 
Any help? THANKS!

sendformContact_test.php

Link to comment
https://forums.phpfreaks.com/topic/275418-checkbox-group-form-submission/
Share on other sites

I think you want to use the foreach to loop through the values of CheckboxGroup1

 

 

$mail_body.= 'Choices: ';
$cbg1=$_REQUEST['CheckboxGroup1']; //just cause I don't like looping through a nested array
foreach ($cbg1 as $value){
$mail_body.=$value."  ";// spaces so the choices don't run together
}

You may also want to sanitize the input with htmlspecialchars() before you mail it to yourself.

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.