mark60480 Posted March 8, 2013 Share Posted March 8, 2013 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 More sharing options...
Barand Posted March 8, 2013 Share Posted March 8, 2013 CheckboxGroup1 will be posted as an array so you would need something like $mail_body .= "Choices: ".join(', ', $_REQUEST['CheckboxGroup1']); Link to comment https://forums.phpfreaks.com/topic/275418-checkbox-group-form-submission/#findComment-1417596 Share on other sites More sharing options...
davidannis Posted March 8, 2013 Share Posted March 8, 2013 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. Link to comment https://forums.phpfreaks.com/topic/275418-checkbox-group-form-submission/#findComment-1417597 Share on other sites More sharing options...
davidannis Posted March 8, 2013 Share Posted March 8, 2013 Barand's solution is more elegant. I recreated a function that already exists. Link to comment https://forums.phpfreaks.com/topic/275418-checkbox-group-form-submission/#findComment-1417598 Share on other sites More sharing options...
mark60480 Posted March 8, 2013 Author Share Posted March 8, 2013 That's perfect Barand. Thanks so much! Link to comment https://forums.phpfreaks.com/topic/275418-checkbox-group-form-submission/#findComment-1417613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.