我的网站上有一张表格,不是由我写的,而且这个表格不是很好(或者可以达到这个问题)所以现在老板要我修理它。目前,提交表单发送emal并打开一条感谢信息。不幸的是,弹出窗口看起来更像是错误消息而不是成功消息,因此我被要求将提交按钮重定向到实际的感谢页面而不是弹出窗口。现在我对PHP不是很大,所以我需要一些帮助。
HTML:
<form>
<div class="row">
<div class="six columns">
<label class="gfield_label" for="Name" style="display: block;">Name<span class="gfield_required">*</span></label>
<input type="text" id="Name" required class="mobile-four"/>
</div>
<div class="six columns">
<label class="gfield_label" for="Company" style="display: block;">Company</label>
<input type="text" id="Company" required class="mobile-four"/>
</div>
</div>
<div class="row">
<div class="six columns mobile-four">
<label class="gfield_label" for="email" style="display: block;">Email<span class="gfield_required">*</span></label>
<input type="email" class="mobile-four" id="email" required />
</div>
<div class="six columns mobile-four">
<label class="gfield_label" for="phone" style="display: block;">Phone<span class="gfield_required">*</span></label>
<input type="phone" class="mobile-four" id="phone" required />
</div>
</div>
<div class="row">
<div class="twelve columns mobile-four">
<label class="gfield_label" for="message" style="display: block;">Message<span class="gfield_required">*</span></label>
<textarea id="message" cols="30" rows="3"></textarea>
</div>
<div class="three columns centered">
<button id="contact-submit-btn" class="btn btn-block btn-danger">Contact us Now!</button>
</div>
</div>
</form>
PHP:
<?php
if($_POST){
$mailBody = "Name:" . $_POST['Name'] . "\nPhone:" . $_POST['phone'] . "\nEmail:" . $_POST['email'] . "\nMessage:\n" . $_POST['message'];
mail("a@harbordev.com","Website request from " . $_POST['Name'], $mailBody);
}
header("location:/thankyou.html");
?>
JS:
$(document).ready(function() {
$("#contact-submit-btn").click(function() {
var form_data = {
Name:$("#Name").val(),
Company:$("#Company").val(),
phone:$("#phone").val(),
email:$("#email").val(),
message:$("#message").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: "/contactsubmit.php",
data: form_data,
cache: false,
success: function(result){
alert(result);
}
});//ajax
return false;
});
});
我希望将提交按钮重定向到&#34; contact-thanks.html&#34;,这不是用PHP编写的。 (thankyou.html是用PHP编写的,但它包含的是你发短信的坦克)。
感谢您的帮助
答案 0 :(得分:1)
成功处理程序中的这样的事情会:
window.location = '/thankyou.html';