2016-07-27 97 views
0

我会尽力解释这一点。表单提交重定向回页面并显示一个模式

我有一个表格上email.php上提交的行动:形式在email.php成功处理

<form data-toggle="validator" role="form" method="POST" action="email.php"> 
         <div class="row"> 
          <!-- Full Name --> 
          <div class="form-group col-lg-4"> 
           <label for="inputName" class="control-label">Name</label> 
           <input type="text" class="form-control" name="inputName" id="inputName" required> 
          </div> 
          <!-- email --> 
          <div class="form-group col-lg-4"> 
           <label for="inputEmail" class="control-label">Email</label> 
           <input type="email" class="form-control" name="inputEmail" id="inputEmail" data-error="Incorrect Email Format" required> 

          </div> 
          <!-- phone number --> 
          <div class="form-group col-lg-4"> 
           <label for="inputTel" class="control-label">Phone Number</label> 
           <input type="text" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" name="inputTel" id="inputTel" data-minlength="10" maxlength="15" class="form-control" placeholder="123-456-7890" data-error="(123)-456-7890 | 1234567890 | 123-456-7890"> 

          </div> 
          <!-- message --> 
          <div class="form-group col-lg-12"> 
           <label for="content" class="control-label">Message</label> 
           <textarea name="content" id="content" class="form-control" rows="6" data-minlength="5" data-error="Message Must be longer"></textarea> 

          </div> 
          <!-- button --> 
          <div class="form-group col-lg-12"> 
           <button type="submit" class="btn btn-default">Submit</button> 
          </div> 
         </div> 
        </form> 

后,我希望它回到表格位于页面和显示“谢谢”莫代尔我创造

目前我在email.php(验证后):

 echo "<script> 

    $(window).load(function(){ 
     $('#myModal').modal('show'); 
    }); 
    window.location.href="Websitename"; 
</script>"; 

这是行不通的。会发生什么情况是页面被重定向,但不显示模式。

任何人都可以提供任何帮助吗?

+0

你为什么不用一个按钮重新定向到'Websitename'而点击时显示模式?或者只是设置超时运行'window.location.href =“Websitename”' – TTCC

回答

0

我认为这个问题是在

 window.location.href="Websitename"; 

在浏览器中看到这条线,她会自动定位,这意味着马上做出新的请求的浏览器。 让我解释一下: 你的表单发送请求到email.php ----->将响应作为一个javascript-> javascript请求发送到“网站名称”。 为了解决这个问题,你应该把window.location.href放在timeout函数内,并且在window.load之后触发这个超时。 请检查:

echo "<script> 
      function deferredFunction(){ 
window.location.href="Websitename"; 
    } 
     $(window).load(function(){ 
      $('#myModal').modal('show'); 
      setTimeout(deferredFunction,5000); 
     }); 
    </script>"; 

希望有助于!

+0

迟到35秒:D –

+0

谢谢! 不幸的是,这并没有解决我的问题。我仍然挂在email.php线程上,没有显示重定向或模式。 是否email.php必须包含任何引导程序链接才能正常工作? –

+0

检查评论(http://stackoverflow.com/questions/4584373/difference-between-window-load-and-document-ready-functions)。请将$(window).load更改为$(document).ready –

相关问题