Jump to content


Help returning values from a checkbox to email

  • Please log in to reply
2 replies to this topic

#1 dthomas31uk

  • Members
  • PipPip
  • Member
  • 14 posts

Posted 15 September 2006 - 06:49 AM

Hi, I have a page http://www.athene-ha...ppointment.html with a number of checkboxes. What I need to do is allow the user to check the boxes and when submit is clicked the data is sent to an email address. How can I achieve this have done it before with textboxes etc., but with the checkboxes no data is passed. Think I need an array in my php, any ideas how I can achieve this. The following is code to what I used when using textboxes, hope someone can point me in the right direction. Cheers guys.

$option = $_POST["SalonVsPrices_Key"];
$email = $_POST["email"];
$message = $_POST["message"];
$date = date ("j m Y hh:mm", strtotime("now"));
$message = $_POST["message"];
$message = <<<EOF
Enquiry from $name \r\n
Email address: $email\r\n
Made on $date\r\n
who left the following message: \r\n


$to = "enquiries@exploitation.org.uk"; // To email address
$subject = "Enquiry from Athene Hair and Beauty Contact Page";
$headers = 'From: $to'. "\r\n" .
'Reply-To: $to' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers))
header("Location: ContactResponse.html");
echo "error in mail";

#2 jvrothjr

  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 15 September 2006 - 03:28 PM

Do you use an array to build your checkbox listing

         foreach ($filen as $value){
            echo "<input type='checkbox' name='chkbx[]' value='".$value."' checked>$value<br>";

If so you will need a foreach loop or something the get the values back out

If you build is one line at a time the maybe your displaying the value to the screen but not setting the variable to it

example of display and setting variables
            echo "<input type='checkbox' name='chkbx1' value='opt1' checked>Option 1<br>";
            echo "<input type='checkbox' name='chkbx2' value='opt2'>Option 2<br>";

example on display only
            echo "<input type='checkbox' name='chkbx1' checked>Option 1<br>";
            echo "<input type='checkbox' name='chkbx2'>Option 2<br>";

If you understand everything you know nothing!


#3 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 September 2006 - 03:44 PM

in your case not passing data from unchecked checkboxes is a good thing.

I checked your page and it looks like all of your checkboxes have the same name. they need to be different, or the values will just overwrite themselves.

This will only send the item name and the price of the items selected. if the items aren't selected by the visitor, they don't come through.

<input type="checkbox" name="Haircut with shampoo with Norah" value="21.95">

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users