I’m working on a form submit template for consumer feedback for a customer’s website. The issue I’m having is that all the variable options are being carried through and posted in the email, and I only want the selected checkboxes or fields that contain input text to show up on the back end. HTML form code and PHP command code are included below:
HTML Form Code:
<!-- Customer Feedback Form -->
<form method="POST" action="customer-feedback.php">
<p>How did you hear about us?
<p><input type="checkbox" name="Event"> Event (which one): <input type="text" name="Which_Event" size="30">
<p><input type="checkbox" name="Website"> Website (which one): <input type="text" name="Which_Website" size="30">
<p><input type="checkbox" name="Search_Engine"> Search Engine
<p><input type="checkbox" name="Word_of_Mouth"> Word of Mouth
<br>
<p>What type of racing interests you? (check all that apply)
<p><input type="checkbox" name="IndyCar"> IndyCar
<p><input type="checkbox" name="Formula_One"> Formula One
<p><input type="checkbox" name="Sprint_Midgets"> Sprint, Midgets
<p><input type="checkbox" name="Nascar"> NASCAR
<p><input type="checkbox" name="Other"> Other (which kind): <input type="text" name="Which_Kind" size="30">
<p><input type="checkbox" name="Like_All"> I like all auto racing
<p><input type="checkbox" name="Like_None"> I am not an auto racing fan
<p><input type="submit" name="submit" value="Submit">
</form>
<!-- End Customer Feedback Form -->
PHP Code from (customer-feedback.php)
[php]
<?php
// Website Contact Form Generator
// http://www.tele-pro.co.uk/scripts/contact_form/
// Get posted data into local variables
$EmailTo = "
[email protected]";
$Communication = "Customer Feedback";
$Event = Trim(stripslashes($_POST['Event']));
$Which_Event = Trim(stripslashes($_POST['Which_Event']));
$Website = Trim(stripslashes($_POST['Website']));
$Which_Website = Trim(stripslashes($_POST['Which_Website']));
$Search_Engine = Trim(stripslashes($_POST['Search_Engine']));
$Word_of_Mouth = Trim(stripslashes($_POST['Word_of_Mouth']));
$IndyCar = Trim(stripslashes($_POST['IndyCar']));
$Formula_One = Trim(stripslashes($_POST['Formula_One']));
$Sprint_Midgets = Trim(stripslashes($_POST['Sprint_Midgets']));
$Nascar = Trim(stripslashes($_POST['Nascar']));
$Other = Trim(stripslashes($_POST['Other']));
$Which_Kind = Trim(stripslashes($_POST['Which_Kind']));
$Like_All = Trim(stripslashes($_POST['Like_All']));
$Like_None = Trim(stripslashes($_POST['Like_None']));
// validation
$validationOK=true;
if (!$validationOK) {
print "";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Discovered via: Event";
$Body .= $Event;
$Body .= "\n";
$Body .= "Which Event: ";
$Body .= $Which_Event;
$Body .= "\n";
$Body .= "Discovered via: Website";
$Body .= $Website;
$Body .= "\n";
$Body .= "Which Website: ";
$Body .= $Which_Website;
$Body .= "\n";
$Body .= "Discovered via: Search Engine";
$Body .= $Search_Engine;
$Body .= "\n";
$Body .= "Discovered via: Word of Mouth";
$Body .= $Word_of_Mouth;
$Body .= "\n";
$Body .= "Fan of: IndyCar";
$Body .= $IndyCar;
$Body .= "\n";
$Body .= "Fan of: Formula One";
$Body .= $Formula_One;
$Body .= "\n";
$Body .= "Fan of: Sprint, Midgets";
$Body .= $Sprint_Midgets;
$Body .= "\n";
$Body .= "Fan of: NASCAR";
$Body .= $Nascar;
$Body .= "\n";
$Body .= "Fan of: Other";
$Body .= $Other;
$Body .= "\n";
$Body .= "Which Kind: ";
$Body .= $Which_Kind;
$Body .= "\n";
$Body .= "I like all auto racing";
$Body .= $Like_All;
$Body .= "\n";
$Body .= "I am not an auto racing fan";
$Body .= $Like_None;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Communication, $Body, "From: ");
// redirect to success page
if ($success){
print "";
}
else{
print "";
}
?>
[/php]
Thanks