連絡先ページ用に持っていたPHPコード(ドロップダウン選択なし、すべてのテキストフィールドなし)を完全に機能させようとしています。しかし、ドロップダウン選択で機能させようとすると、機能せず、エラーが発生し続けます。
フォームの HTML コードは次のとおりです。
<form action="order.php" method="post" id="contactform">
<ul id="questions">
<li> <p>category</p> <select data-placeholder="Select a category" name="category" id="selZOX" style="display: none;" class="chzn-done"> <option></option><option value="Snack & Quick Meals" data-connection="snackSelect">Snack & Quick Meals</option><option value="Wraps" data-connection="wrapSelect">Wraps</option><option value="Breads" data-connection="breadSelect">Breads</option><option value="Chicken Entrees" data-connection="chickenSelect">Chicken Entrees</option><option value="Lahawajawaab Mutton" data-connection="laSelect">Lahawajawaab Mutton</option><option value="Rice Dishes" data-connection="riceSelect">Rice Dishes</option><option value="Vegetarian" data-connection="vegSelect">Vegetarian</option> </select><div id="selZOX_chzn" class="chzn-container chzn-container-single" style="width: 300px;"><a href="javascript:void(0)" class="chzn-single" tabindex="0"><span>Snack & Quick Meals</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 298px; top: 27px;"><div class="chzn-search"><input type="text" autocomplete="off" style="width: 263px;" tabindex="-1"></div><ul class="chzn-results"><li id="selZOX_chzn_o_1" class="active-result result-selected" style="">Snack & Quick Meals</li><li id="selZOX_chzn_o_2" class="active-result" style="">Wraps</li><li id="selZOX_chzn_o_3" class="active-result" style="">Breads</li><li id="selZOX_chzn_o_4" class="active-result" style="">Chicken Entrees</li><li id="selZOX_chzn_o_5" class="active-result" style="">Lahawajawaab Mutton</li><li id="selZOX_chzn_o_6" class="active-result" style="">Rice Dishes</li><li id="selZOX_chzn_o_7" class="active-result" style="">Vegetarian</li></ul></div></div> <span class="divider"></span> </li><li> <p>meal</p> <select data-placeholder="Select a meal" name="meal" id="selJ3O" style="display: none;" class="chzn-done"> <option></option><option value="Samosa - $2.99" data-connection="spiceSelect">Samosa - $2.99</option><option value="Aloo Tiki - $2.99" data-connection="spiceSelect">Aloo Tiki - $2.99</option><option value="Chana Samosa - $4.99" data-connection="spiceSelect">Chana Samosa - $4.99</option><option value="Tiki Chaat - $4.99" data-connection="spiceSelect">Tiki Chaat - $4.99</option><option value="Choley Bhaturey - $7.99" data-connection="spiceSelect">Choley Bhaturey - $7.99</option> </select><div id="selJ3O_chzn" class="chzn-container chzn-container-single" style="width: 300px;"><a href="javascript:void(0)" class="chzn-single" tabindex="0"><span>Aloo Tiki - $2.99</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 298px; top: 27px;"><div class="chzn-search"><input type="text" autocomplete="off" style="width: 263px;" tabindex="-1"></div><ul class="chzn-results"><li id="selJ3O_chzn_o_1" class="active-result" style="">Samosa - $2.99</li><li id="selJ3O_chzn_o_2" class="active-result result-selected" style="">Aloo Tiki - $2.99</li><li id="selJ3O_chzn_o_3" class="active-result" style="">Chana Samosa - $4.99</li><li id="selJ3O_chzn_o_4" class="active-result" style="">Tiki Chaat - $4.99</li><li id="selJ3O_chzn_o_5" class="active-result" style="">Choley Bhaturey - $7.99</li></ul></div></div> <span class="divider"></span> </li><li> <p>spicy</p> <select data-placeholder="Select an option" name="spicy" id="selJME" style="display: none;" class="chzn-done"> <option></option><option value="Very Spicy" data-connection="deliverSelect">Very Spicy</option><option value="Spicy" data-connection="deliverSelect">Spicy</option><option value="Medium" data-connection="deliverSelect">Medium</option><option value="Mild" data-connection="deliverSelect">Mild</option><option value="Not Spicy" data-connection="deliverSelect">Not Spicy</option> </select><div id="selJME_chzn" class="chzn-container chzn-container-single" style="width: 300px;"><a href="javascript:void(0)" class="chzn-single" tabindex="0"><span>Medium</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 298px; top: 27px;"><div class="chzn-search"><input type="text" autocomplete="off" style="width: 263px;" tabindex="-1"></div><ul class="chzn-results"><li id="selJME_chzn_o_1" class="active-result" style="">Very Spicy</li><li id="selJME_chzn_o_2" class="active-result" style="">Spicy</li><li id="selJME_chzn_o_3" class="active-result result-selected" style="">Medium</li><li id="selJME_chzn_o_4" class="active-result" style="">Mild</li><li id="selJME_chzn_o_5" class="active-result" style="">Not Spicy</li></ul></div></div> <span class="divider"></span> </li><li> <p>delivery</p> <select data-placeholder="Select an option" name="delivery" id="selXE9" style="display: none;" class="chzn-done"> <option></option><option value="Yes">Yes</option><option value="No">No</option> </select><div id="selXE9_chzn" class="chzn-container chzn-container-single" style="width: 300px;"><a href="javascript:void(0)" class="chzn-single" tabindex="0"><span>No</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 298px; top: 27px;"><div class="chzn-search"><input type="text" autocomplete="off" style="width: 263px;" tabindex="-1"></div><ul class="chzn-results"><li id="selXE9_chzn_o_1" class="active-result" style="">Yes</li><li id="selXE9_chzn_o_2" class="active-result result-selected" style="">No</li></ul></div></div> <span class="divider"></span> </li></ul>
<div id="preloader" style="display: none;"></div>
<div class="clear"></div>
<ul id="order2">
<li>
<p>Any Additional Comments</p>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
</ul>
<span class="divider"></span>
<div class="clear"></div>
<ul id="order">
<li>
<p>Name</p>
<input id="name" name="name" class="text">
</li>
<li class="right">
<p>Email Address</p>
<input id="email" name="email" class="text">
</li>
<li>
<p>Phone Number</p>
<input id="phone" name="phone" class="text">
</li>
<li class="right">
<p>Address</p>
<input id="address" name="address" class="text">
</li>
<li>
<p>City</p>
<input id="city" name="city" class="text">
</li>
<li class="right">
<p>Zip Code</p>
<input id="zip" name="zip" class="zip">
</li>
</ul>
<div class="clear"></div>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send">
<div class="clr"></div>
</li>
</form>
ここに私のPHPコードがあります:
<?php
if(isset($_POST['email'])) {
$email_to = "email@myemail.com";
$email_subject = "subject";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted: <br />";
echo $error."<br />";
echo "Please fix these errors.<br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['address']) ||
!isset($_POST['city']) ||
!isset($_POST['zip']) ||
!isset($_POST['category']) ||
!isset($_POST['meal']) ||
!isset($_POST['spicy']) ||
!isset($_POST['delivery']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$phone = $_POST['phone']; // not required
$phone = $_POST['address']; // not required
$phone = $_POST['city']; // not required
$phone = $_POST['zip']; // not required
$category = $_POST['category']; // not required
$meal = $_POST['meal']; // not required
$spicy = $_POST['spicy']; // not required
$delivery = $_POST['delivery']; // not required
$message = $_POST['message']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "Zip: ".clean_string($zip)."\n";
$email_message .= "Meal Category: ".clean_string($category)."\n";
$email_message .= "Meal: ".clean_string($meal)."\n";
$email_message .= "How Spicy: ".clean_string($spicy)."\n";
$email_message .= "Delivery: ".clean_string($delivery)."\n";
$email_message .= "Other Details: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
echo 'Thank you, your message has been sent! <br /> We will review your submission and contact you as soon as possible.';
}
?>
頭の中の私のスクリプト:
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$.post(action, {
category: $('#category').val(),
meal: $('#meal').val(),
spicy: $('#spicy').val(),
delivery: $('#delivery').val(),
email: $('#email').val(),
phone: $('#phone').val(),
address: $('#address').val(),
city: $('#city').val(),
zip: $('#zip').val(),
message: $('#message').val()
},
function(data){
$('#contactform #submit').attr('disabled','');
$('.response').remove();
$('#contactform').before('<p class="response">'+data+'</p>');
$('.response').slideDown();
if(data=='Thank you, your message has been sent! <br /> We will review your submission and contact you as soon as possible.') $('#contactform').slideUp();
}
);
return false;
});
});
// ]]>
</script>
どんな助けでも大歓迎です。ありがとう!