Jump to content

Need help with populating database with drop down form


energysuperstore09

Recommended Posts

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      = 'margaret@synergy-mg.com,susan@synergy-mg.com,pondertheweb@gmail.com';
	$to = 'sales@govpayexp.com';
	$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: Margaret@synergy-mg.com,susan@synergy-mg.com' . "\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.

Link to comment
Share on other sites

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".

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.