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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)