?
Solved

Php email checkboxes

Posted on 2008-01-29
4
Medium Priority
?
242 Views
Last Modified: 2010-05-19
I have a simple question (I hope). I have a simple php email script and a simple html form. I need to know how to code the checkbox fields in the form, as well as how to include them in the email php script. Thanks.
0
Comment
Question by:isaacr25
4 Comments
 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 200 total points
ID: 20774670
you have to print those form design with html design in the mail body script ...which will be sending through the mail..

0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 1200 total points
ID: 20774673
Isaac,

The easiest thing to do is to have the checkbox fields have different names.  Then, PHP will treat each one as a separate field.

If you want to store all checked values in a single field, that's certainly possible, but a bit trickier.
0
 
LVL 19

Assisted Solution

by:v2Media
v2Media earned 400 total points
ID: 20774756
The easiest way is to let php group the checkbox values into an array. This is done by giving every checkbox in the form that's grouped together the same name and a set of square brackets appended to that name e.g.

<input type="checkbox" name="options[]" value="option one value" />
<input type="checkbox" name="options[]" value="option two value" />
<input type="checkbox" name="options[]" value="option three value" />

The form values are then accessed in php like so:
<?php
 
$arr_options = (!empty($_POST['options'])) ? $_POST['options'] : false;
 
if($arr_options) {
 
  foreach($arr_options as $k => $v) {
 
    echo $k . ' option = ' . $v;
 
  }
 
}
 
?>

Open in new window

0
 
LVL 25

Assisted Solution

by:Marcus Bointon
Marcus Bointon earned 200 total points
ID: 20783933
Bear in mind that unchecked checkboxes do not get submitted with the form, so you need to work out which ones were unchecked by elimination.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question