Reputation: 4946
Here is the form I am using:
<form action="scripts/contactscript.php" method="post" id="contactform">
<ol>
<li>
<label for="name">Your Name <span class="red">*</span></label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">Your email <span class="red">*</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="interested">Interested In <span class="red">*</span></label>
<select id="interested" name="interested">
<option value="">-- Please Select --</option>
<option value="GeneralInformation">General Information</option>
<option value="PurchasingABike">Purchasing A Bike</option>
</select>
</li>
<li>
<label for="message">Message <span class="red">*</span></label>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
<div class="clr"></div>
</li>
</ol>
</form>
And here is the script it is posting to:
<?php
if(!$_POST) exit;
$email = $_POST['email'];
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message','interested');
$required = array('name','email','message');
$your_email = "[email protected]";
$email_subject = "Little Bike Riders Message: ".$_POST['subject'];
$email_content = "New message:\n\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n\n" ;
}
if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>
Here is what is shown in the email when it is sent:
New message:
name: Jon Harding
email: [email protected]
message: Test
interested:
Upvotes: 2
Views: 934
Reputation: 632
You have choosen the default entry -- Please Select --
when submitting your form which has the option value ""
and that is being displayed in your email. I have tried your example locally and if I select one of the other options it is working.
Edit:
You are using the following code to submit your form:
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
subject: $('#subject').val(),
message: $('#message').val()
},
function(data){
$('#contactform #submit').attr('disabled','');
$('.response').remove();
$('#contactform').before('<p class="response">'+data+'</p>');
$('.response').slideDown();
if(data=='Message sent!') $('#contactform').slideUp();
}
);
return false;
});
});
You forgot to add the value of the interested element interested: $('#interested').val()
to the object which you are passing to the $.post method.
Upvotes: 1