Two Submit Buttons

Hello,
I am trying to have a form on my web page where my visitors enter their name in one input field and then choose either attending or not attending buttons with it then emailing me their name and a different email subject depending which button they pushed. I have gotten everything to work sorta. When the name is inputted and only one button is pushed I get two emails. On my html page the two buttons are named coming and notcoming. My code is below. Any help is greatly appreciated.

[php]<?php
if(!isset($_POST[‘coming’]))
{
//This page should not be accessed directly. Need to submit the form.
echo “error; you need to submit the form!”;
}
$name = $_POST[‘name’];

//Validate first
if(empty($name))
{
echo “Name is mandatory!
Please press back”;
exit;
}

$email_from = ‘[email protected]’;//<== update the email address
$email_subject = “Attending the Wedding”;
$email_body = “$name is coming to the Wedding.\n”.

$to = "[email protected]";//<== update the email address
$headers = "From:[email protected] \r\n";

//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header(‘Location: http://www.google.ca’);

if(!isset($_POST[‘notcoming’]))
{
//This page should not be accessed directly. Need to submit the form.
echo “error; you need to submit the form!”;
}
$name = $_POST[‘name’];

//Validate first
if(empty($name))
{
echo “Name is mandatory!
Please press back”";
exit;
}

$email_from = ‘[email protected]’;//<== update the email address
$email_subject = “Not Attending the Wedding”;
$email_body = “$name is not coming to the Wedding.\n”.

$to = "[email protected]";//<== update the email address
$headers = “From: [email protected] \r\n”;

//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header(‘Location: google.ca’);

// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?> [/php]

Why use two submit buttons it is overcomplicating matters.

Just use a radio input for coming / not coming and then one submit button.

The you just need one email header variable to be set and then the rest of the email code is the same.

I agree with [member=49048]Valkrider[/member], you are over complicating things.

KISS - Keep It Simple Stupid.

Sponsor our Newsletter | Privacy Policy | Terms of Service