我使用淡出的ajax联系表单并显示感谢信息。我在提交表单后也收到邮件。但是它没有在表单中输入任何数据。我认为表单数据没有传递给handler.php..Any有帮助吗?
ajax.js
.loading {width: 100px}
handler.php
$(function() {
var theForm = $("#memberform");
theForm.validate({
submitHandler: function(theForm) {
$('#loader', theForm).html('Please Wait...');
$.ajax({
type: "POST",
url: "handler.php",
data: $(theForm).serialize(),
timeout: 20000,
success: function(msg) { $(theForm).fadeOut((500, function(){
$(theForm).html("<h2>Thank you. We will contact you shortly.</h2>").fadeIn();
}));
},
error: $('.thanks').show()
});
return false;
}
});
});
我在head标签顶部链接的脚本。
<?php
$to = 'something@gmail.com';
$subject = 'Contact Form';
$name = $_POST['senderName'];
$phone = $_POST['senderNumber'];
$email = $_POST['senderEmail'];
$message = $_POST['senderComments'];
$MESSAGE_BODY = "Name: ".$name."<br>";
$MESSAGE_BODY .= "Contact No: ".$phone."<br>";
$MESSAGE_BODY .= "Email: ".$email."<br>";
$MESSAGE_BODY .= "Message: ".nl2br($message)."<br>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Companyname' . "\r\n";
$headers .= 'Reply-To: something.com' . "\r\n";
$headers .= 'Cc: something@gmail.com' . "\r\n";
//$headers .= 'Bcc: example@example.com' . "\r\n";
mail($to, $subject, $MESSAGE_BODY, $headers);
?
我编辑了带有重写规则的web.config文件,以隐藏域中的.php扩展名...
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript" src="met.js"></script>
答案 0 :(得分:0)
试试这个,也许有帮助
$(function() {
var theForm = $("#memberform");
var data = theForm.serialize();
theForm.validate({
submitHandler: function(theForm) {
$('#loader', theForm).html('Please Wait...');
$.ajax({
type: "POST",
url: "handler.php",
data: data,
timeout: 20000,
success: function(msg) { $(theForm).fadeOut((500, function(){
$(theForm).html("<h2>Thank you. We will contact you shortly.</h2>").fadeIn();
}));
},
error: $('.thanks').show();
});return false;
}
});
});
答案 1 :(得分:0)
Thanks for helping me with the problem.Just found the answer by deleting some rewrite rule.The problem is in web.config.Removing the rewrite rule makes the form work just fine...
Or if you want to keep the rewrite rule and submit the form, edit the ---url: "handler.php"--- line to url: "handler" and the form works just fine.