Forum Moderators: coopster

Message Too Old, No Replies

PHP mail() Form checkbox

How do you pass the checkbox and radio button info from a form?

         

Wild_Rose

2:27 pm on Jan 26, 2006 (gmt 0)

10+ Year Member



Hi, i'm relatively new to PHP, and I have a form set up and I'm using the mail() to send the information to an email account.

All the information is being passed fine, but I'm having trouble with the checkboxes. I've got the info to pass if I set the checkbox to "checked" but it's not appropriate to do this - I have a list of 8 checkboxes.

Is there a way that php can handle this, or do I need to use javascript? If so can someone point me in the right direction. Thanks.

Also the radio buttons aren't passing information either, but I'm assuming that its the same reason.

I'm using code like this

name="field[]" "value="choice1"
name="field[]" "value="choice2"

Twisted Mind

2:48 pm on Jan 26, 2006 (gmt 0)

10+ Year Member



I dont really know what you are saying or meaning with these checkboxes do you mean you got the value already but that you dont get the boxes to be checked or what?

anyways if it is what i think you mean (probally is not)
you could do this <input type=checkbox name=blah <?if (value == 'thevalueifitischecked'){echo"checked";}?>>

Salsa

2:49 pm on Jan 26, 2006 (gmt 0)

10+ Year Member



This comes up here quite a bit. It's fairly easy to do what you want, and no JavaScript is needed. Here are some other threads [google.com] where it's been discussed.

Wild_Rose

4:20 pm on Jan 26, 2006 (gmt 0)

10+ Year Member



Hi thanks twisted mind, but I couldn't get that to work.

I've also tried to search through other posts and I'm now realising just how much I don't know!

This is the code I'm using:

--------------------------
if ($_POST) {
if (get_magic_quotes_gpc()) {
foreach ($_POST as $key => $value) {
$temp = stripslashes($value);
$_POST[$key] = $temp;

}
}
$to = 'email@example.com';
$subject = 'Feedback from website';
// message goes here
$message = "Contact: " . $_POST['eventtype'] . "\n";
$message .= "Event Date: " . $_POST['eventdate'] . "\n";

// headers go here
$headers = "From: feedback@example.com\n";
$headers .= "Reply-To: " . $_POST['email'] . "\n";
$headers .= "Cc: email@example.com\n";
$headers .= "Content-type: text/plain; charset=UTF-8";

$sent = mail($to, $subject, $message, $headers);

}

----------------------------------------------
<dt>
<label for="Service">Service</label>
</dt>
<dd>
<input type="checkbox" name="service[]" value="service1" >
Service 1 </dd>
<dd>
<input type="checkbox" name="service[]" value="service2" >
Service 2 </dd>

--------------------------------------------

It's now sending the word "Array" via email.

Do I need to use a forloop, or something else? Any help would be great, thanks.