dongwen6743 2014-05-07 17:08
浏览 69
已采纳

HTML表单同时提交和重定向

I have a form on my website that was not written by me and the person who did it wasn't very good (or reachable for that matter) so now by bosses want me to fix it. Currently the form on submit sends an emal and opens up a thank you message. Unfortunately that pop-up looks much more like an error message than a success message, so I was asked to redirect the submit button to an actually thank you page instead of a pop-up. Now I'm not very vast with PHP so I need some help.

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'] . "
Phone:" . $_POST['phone'] . "
Email:" . $_POST['email'] . "
Message:
" . $_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;
        });
});

I would like the submit button to redirect to "contact-thanks.html", which isn't written in PHP. (thankyou.html is written in PHP, but all it contains is the tank you text).

Thanks for the help

  • 写回答

1条回答 默认 最新

  • dpecb06062 2014-05-07 17:13
    关注

    Something like this in the success handler would do:

    window.location = '/thankyou.html';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用