energysuperstore09 Posted November 25, 2009 Share Posted November 25, 2009 I have a mini form on my page and would like to submit the info for the drop down into the database along with an email sent to me as well. here is what the form looks like: <form method="post" name="form_help" id="form_help" action="submit.php"> <div id="form_wrapper"> <h1>Schedule a complimentary consultation with one of our experts regarding payment processing systems for government agencies.</h1> <input type="hidden" name="page" value="cc_services" /> <input type="text" name="fname" id="fname" value="First Name" class="required" /> <input type="text" name="lname" id="lname" value="Last Name" class="required" /> <input type="text" name="phone" id="phone" value="Phone" class="required phoneUS" /> <input type="text" name="email" id="email" value="e-Mail" class="required email" /> <input type="text" name="agency" id="agency" value="Agency" class="required" /> <input type="text" name="county" id="county" value="County" class="required" /> <input type="text" name="state" id="state" value="State" class="required" /> <select name="mydropdown"> <option value="How">How did you hear about us?</option> <option value="Internet">Internet Search</option> <option value="Colleague">Colleague</option> <option value="Advertisement">Advertisement</option> <option value="Other">Other</option> </select> <textarea name="more" id="more">Tell us more:</textarea> <input type="submit" value="" id="submit" /> <div id="thecaptcha" style="clear:both;"> <input type="hidden" value="" name="js" id="js" /> </div> </div> </form> and here is what my submit page looks like: <?php if(array_key_exists('fname', $_POST) && array_key_exists('lname', $_POST) && array_key_exists('email', $_POST) && array_key_exists('phone', $_POST) && array_key_exists('more', $_POST) && array_key_exists('js', $_POST) ){ if($_POST['js'] != "yes"){ die("Sorry, you must have javascript enabled to use this form. Please use the <a href='http://govpayexp.com/govpay-contact.php'>Contact Us form</a> if you are not able to enable javascript."); } include "classes/cs.validation.class.php"; $validator = new csFormValidation; $form_fields = cleanParams($_POST); $validator->checkEmailFormat($form_fields['email'],'Email Address'); $validator->isValidEmailComment($form_fields['more']); if (count($validator->errorMessages)>0) { echo "There was a problem with the information you entered. Please review and try again."; } else { //$to = '[email protected],[email protected],[email protected]'; $to = '[email protected]'; $subject = "Contact form from GovPayEXP.com ( " . $form_fields['page'] . " )"; $email = $form_fields['email']; $message = "<html> <head> <title>GovPayEXP</title> </head> <body style='font-size:16px;'>"; $name = $form_fields['fname'] . " " . $form_fields['lname']; $message .= "Name: " . $name . "<br />"; $message .= "Phone: " . $form_fields['phone'] . "<br />"; $message .= "Email: " . $form_fields['email'] . "<br />"; $message .= "Agency: " . $form_fields['agency'] . "<br />"; $message .= "County: " . $form_fields['county'] . "<br />"; $message .= "State: " . $form_fields['state'] . "<br />"; $message .= "Tell us more: " . $form_fields['more'] . "<br />"; $message .= "</body></html>"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: ' . $name . '<' . $email . '>' . "\r\n"; $headers .= 'Reply-To: ' . $name . '<'. $email . '>' . "\r\n"; $headers .= 'Bcc: [email protected],[email protected]' . "\r\n"; $message = nl2br($message); mail($to, $subject, $message, $headers); include "../admin/db.php"; $date = date("Y/m/d H:i:s"); $users = mysql_query("INSERT into mini_contact set name = '" . mysql_real_escape_string($form_fields['fname'] . " " . $form_fields['lname']) . "', phone = '" . mysql_real_escape_string($form_fields['phone']) . "', email = '" . mysql_real_escape_string($form_fields['email']) . "', question = '" . mysql_real_escape_string($form_fields['more']) . "' , agency = '" . mysql_real_escape_string($form_fields['agency']) . "' , county = '" . mysql_real_escape_string($form_fields['county']) . "' , state = '" . mysql_real_escape_string($form_fields['state']) . "', page = '" . $form_fields['page'] . "', date = '" . $date . "'"); header('Location: ../thanks.php'); } } else { echo "There was a problem with the information you entered. Please review and try again."; } function cleanParams($key_value_pair_array) { $newLines = array("\n", "\r", "\r\n", "\n\r"); foreach ($key_value_pair_array as $pk => $pv) { $key_value_pair_array[$pk] = str_replace($newLines, " ", $pv); $values[$i] = str_replace($newLines, " ", $values[$i]); } return $key_value_pair_array; } ?> Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/182925-need-help-with-populating-database-with-drop-down-form/ Share on other sites More sharing options...
energysuperstore09 Posted November 25, 2009 Author Share Posted November 25, 2009 Can anybody help me out with this? Quote Link to comment https://forums.phpfreaks.com/topic/182925-need-help-with-populating-database-with-drop-down-form/#findComment-965523 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 I might be misunderstanding what you need help with but, It's the same procedure as if you were just inserting a text-field (via $_POST) into a database. $_POST['mydropdown'] Quote Link to comment https://forums.phpfreaks.com/topic/182925-need-help-with-populating-database-with-drop-down-form/#findComment-965534 Share on other sites More sharing options...
energysuperstore09 Posted November 25, 2009 Author Share Posted November 25, 2009 I was wanting to know how it wuld look in the submit.php file that I posted. And how would send the results in the email that is also in the submit.php file. Quote Link to comment https://forums.phpfreaks.com/topic/182925-need-help-with-populating-database-with-drop-down-form/#findComment-965541 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 Then yes, you'd just use $_POST['mydropdown']. $_POST['mydropdown'] would hold "whatever" is in the VALUE-attribute of the selected <option> tag. <select name="mydropdown"> <option value="How">How did you hear about us?</option> <option value="Internet">Internet Search</option> <option value="Colleague">Colleague</option> <option value="Advertisement">Advertisement</option> <option value="Other">Other</option> </select> If someone selected the first option, and you echo'd $_POST['mydropdown'], you'd see "How". If someone selected the second option, and you echo'd $_POST['mydropdown'], you'd see "Internet". Quote Link to comment https://forums.phpfreaks.com/topic/182925-need-help-with-populating-database-with-drop-down-form/#findComment-965549 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.