Sending results of dropdown selection on a contact form

Hi Everyone

I am having a problem (well, not so much a problem as a total mindblank)…

I am trying to code a contact form which contains a dropdown selection box. I know how to send all the fields to the php script except the dropdown selection.

If anyone can help I would really appreciate it.

The contact form code is (html):

<form name="contactformlite" method="post" action="lite_process.php" onsubmit="return validate.check(this)"> <table width="400px" class="cflite"> <tr> <td colspan="2"> <p style="text-align:center">Fields marked with <span class="required_star"> * </span> are required.</p> </td> </tr> <tr> <td valign="top" class="cflite_td"> <label for="Full_Name" class="required">Name<span class="required_star"> * </span></label> </td> <td valign="top" class="cflite_td"> <input type="text" name="Full_Name" id="Full_Name" maxlength="80" style="width:250px"> </td> </tr> <tr> <td valign="top" class="cflite_td"> <label for="Email_Address" class="required">Email<span class="required_star"> * </span></label> </td> <td valign="top" class="cflite_td"> <input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:250px"> </td> </tr> <tr> <td valign="top"><label for="Subject">Subject<span class="required_star"> * </span></label></td> <td valign="top"><select id="Subject" name="Subject"> <option value="Please Select" selected="selected">Please Select</option> <option value="Option 1">Career Opportunities</option> <option value="Option 2">Request for Services</option> <option value="Option 3">General Information</option> </select></td> </tr> <tr> <td valign="top" class="cflite_td"> <label for="Your_Message" class="required">Message<span class="required_star"> * </span></label> </td> <td valign="top" class="cflite_td"> <textarea style="width:250px;height:120px" name="Your_Message" id="Your_Message" maxlength="2000"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center" class="cflite_td"> <input type="submit" value=" Submit Form "></td> </tr> </table> </form>

The PHP form that processes the contact form is:

[php]<?php
include “_validation.php”;
include “_configuration.php”;

if(isset($_POST[‘Email_Address’])) {

include 'lite_settings.php';

function died($error) {
	echo "Sorry, but there were error(s) found with the form you submitted. ";
	echo "These errors appear below.<br /><br />";
	echo $error."<br /><br />";
	echo "Please go back and fix these errors.<br /><br />";
	die();
}

if(!isset($_POST['Full_Name']) ||
	!isset($_POST['Email_Address']) ||
	!isset($_POST['Telephone_Number']) ||
	!isset($_POST['Your_Message'])) {
	died('We are sorry, but there appears to be a problem with the form you submitted.');		
}

$full_name = $_POST['Full_Name']; // required
$email_from = $_POST['Email_Address']; // required
$telephone = $_POST['Telephone_Number']; // not required
$comments = $_POST['Your_Message']; // required

$error_message = "";
$email_exp = "/^[A-Z0-9._%-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}$/";

if(!preg_match($email_exp,$email_from)) {
$error_message .= ‘The Email Address you entered does not appear to be valid.
’;
}
if(strlen($full_name) < 2) {
$error_message .= ‘Your Name does not appear to be valid.
’;
}
if(strlen($comments) < 2) {
$error_message .= ‘The Comments you entered do not appear to be valid.
’;
}

if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\r\n”;

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "Full Name: ".clean_string($full_name)."\r\n";
$email_message .= "Email: ".clean_string($email_from)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header(“Location: $thankyou”);
?>

<?php } die(); ?>

[/php]

lite_settings.php:

[php]

<?php $full_name = $_POST['Full_Name']; // required $email_from = $_POST['Email_Address']; // required $comments = $_POST['Your_Message']; // required ?>

[/php]

I know everything else is fine (as I actually tested it this time…) but I just dont know how to send the dropdown box submission.

Can someone help?

Thanks

Ian

Hi.

Select box value posted to your script just the same as any other form field. In your php code use:
[php]<?php
$select = $_POST[‘Subject’]; // <-- this will contain VALUE of selected option
?>[/php]

Excellent, that fixed it…told you it was a total mindblank…something so simple and I could not even see it was missing… ::slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service