SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Aug 8, 2007, 12:32 #1
- Join Date
- Aug 2007
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
using mail() function to submit form with checkboxes
Hello.
I have an HTML form with checkboxes:
<input type="checkbox" name="vehicle" value="Accent" />Accent<br />
<input type="checkbox" name="vehicle" value="Elantra" />Elantra<br />
...
I want to send the information gathered from the form via the php mail() command, but have yet to figure out how to 'pull' the information from the checkboxes into a variable that I can then output in the email.
Here's what I have right now (It doesn't work!):
$vehicle = $_REQUEST['vehicle'];
(this is what I do for everything other than the checkboxes...)
and then:
$message .= "Vehicles: $vehicle";
What am I doing wrong? I am assuming that the values are stored as array; how can I access them?
THANK YOU very much for your help!
-
Aug 8, 2007, 12:43 #2
Do you want to allow multiple choices?
If so add brackets to the name:
Code HTML4Strict:<input type="checkbox" name="vehicle[]" value="Accent" />Accent<br /> <input type="checkbox" name="vehicle[]" value="Elantra" />Elantra<br />
And in that case:
Code php:$vehicle = implode(',',$_POST['vehicle']);
Also, depending on where in the email this data goes (body, header) and the content type, you might wanna validate it.Saul
-
Aug 8, 2007, 15:04 #3
- Join Date
- Aug 2007
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you so much, it works great! I was so close with my other attempts, but didn't understand that I needed to use $_POST inside the implode() function. Can you tell me why POST instead of REQUEST?
-
Aug 8, 2007, 15:38 #4
$_POST has data sent to the server via HTTP POST, while $_REQUEST combines GET, POST and COOKIE data. It's a matter of good practice to take data from where you expect it to come, in this case POST.
Saul
Bookmarks