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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.