Jump to content

Help returning values from a checkbox to email


dthomas31uk

Recommended Posts

Hi, I have a page http://www.athene-hairandbeauty.co.uk/appointment.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
$message

EOF;

$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");
exit;
}
else
{
echo "error in mail";
};";
Link to comment
Share on other sites

Do you use an array to build your checkbox listing

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

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
[code=php:0]
            echo "<input type='checkbox' name='chkbx1' value='opt1' checked>Option 1<br>";
            echo "<input type='checkbox' name='chkbx2' value='opt2'>Option 2<br>";

[/code]

example on display only
[code=php:0]
            echo "<input type='checkbox' name='chkbx1' checked>Option 1<br>";
            echo "<input type='checkbox' name='chkbx2'>Option 2<br>";

[/code]
Link to comment
Share on other sites

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.

[code=php:0]<input type="checkbox" name="Haircut with shampoo with Norah" value="21.95">[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.