Need to set form to post only selected variables

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">&nbsp;&nbsp;Event (which one):&nbsp;<input type="text" name="Which_Event" size="30">
<p><input type="checkbox" name="Website">&nbsp;&nbsp;Website (which one):&nbsp;<input type="text" name="Which_Website" size="30">
<p><input type="checkbox" name="Search_Engine">&nbsp;&nbsp;Search Engine
<p><input type="checkbox" name="Word_of_Mouth">&nbsp;&nbsp;Word of Mouth
<p>What type of racing interests you?&nbsp;&nbsp;(check all that apply)
<p><input type="checkbox" name="IndyCar">&nbsp;&nbsp;IndyCar
<p><input type="checkbox" name="Formula_One">&nbsp;&nbsp;Formula One
<p><input type="checkbox" name="Sprint_Midgets">&nbsp;&nbsp;Sprint, Midgets
<p><input type="checkbox" name="Nascar">&nbsp;&nbsp;NASCAR
<p><input type="checkbox" name="Other">&nbsp;&nbsp;Other (which kind):&nbsp;<input type="text" name="Which_Kind" size="30">
<p><input type="checkbox" name="Like_All">&nbsp;&nbsp;I like all auto racing
<p><input type="checkbox" name="Like_None">&nbsp;&nbsp;I am not an auto racing fan
<p><input type="submit" name="submit" value="Submit">


<!-- End Customer Feedback Form --> 

PHP Code from (customer-feedback.php)

<?php // Website Contact Form Generator // // 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 ""; } ?>



Sponsor our Newsletter | Privacy Policy | Terms of Service