PDA

View Full Version : php & checkboxes




cwesty
Nov 5, 2006, 01:49 PM
Hi there,

I'm trying to get the checkboxes on my form to pickup and be included in the email to me.. For some reason it doesn't work...

here's the php:
<?php
$to = "email@somewhere";
$subject = "$subject";
$message = "$message";
$from = "$email";
$headers = "From: $from";
$checkbox = "$Yes Please";
$checkbox = "$No Thanks";

mail($to,$subject,$message,$headers,$checkbox);
echo('<h2>Thank you for contacting');; ?>

Any ideas????



frankblundt
Nov 5, 2006, 01:52 PM
just guessing it's because your variables are called $Yes Please and $No Thanks - the spaces mean it's looking for $Yes and $No.

I'd have thought also that they would be radio buttons rather than checkboxes (or can you say Yes and No at the same time?), and that your PHP should be doing an if else query to see which one was checked and generating a variable value in response, rather than looking for a value passed from the checkbox

cwesty
Nov 5, 2006, 01:57 PM
i've just tried amending it to show $Yes and $No, but the same result,
I get an email, but without the checkbox response..

frankblundt
Nov 5, 2006, 02:01 PM
Normally I wouldn't expect a checkbox to pass a value, just whether it was checked or not, the PHP then checks each checkbox to see if checked=checked and assigns a variable value to it at that point based on whether it was true or not

frankblundt
Nov 5, 2006, 02:09 PM
actually, sorry, completely wrong :p -

if ( isset ($_POST['submit'])) {

$yesorno=addslashes($_POST['yesorno']);

$response = "Would you like my spam? ".$yesorno;

... email sending stuff..

} else {

echo "<form action=\"email.php\">

.. other form bits..

<p><input type=\"radio\" checked=\"checked\" value=\"Yes Please!\" name=\"yesorno\"> Yes Please or <input type=\"radio\" value=\"No Thanks\" name=\"yesorno\"> No Thanks</p>";

echo "<p><input type=\"submit\" name=\"submit\" value=\"Email\"><br></p></form>"; // submit

}

frankblundt
Nov 5, 2006, 02:22 PM
Also, I'm presuming that whatever code you're using to build the email is combining both the $message and the $checkbox response into one variable at some point to pass to the email 'body'? You may only need to update the $message variable with

$message = .$checkbox

and the way you have it set at the moment, you will always get a negative response because the second $checkbox = "$No Thanks"; is overwriting the value of $checkbox you set in the line $checkbox = "$Yes Please"; above it