简体   繁体   English

提交表单后重定向页面

[英]Redirect page after form submitting a form

<body onload="document.action.submit()">
<form name="action" method="post" action="https://en.educaplay.com/en/registrar.php" >
<input type="hidden" name="action" value='loginTicket'>

    <input name="ticket" type="text" id="ticket" value="<%= session[:educa_key] %>">
    <input type="submit" name="entrar" id="entrar2" value="Sign in" class="btn">
</form>

Now, I want to redirect the submitter to any page of my choice after the form data has been submitted, but the action resides on another website where I cannot edit. 现在,我想在提交表单数据后将提交者重定向到我选择的任何页面,但是操作位于另一个我无法编辑的网站上。 Is it possible to redirect the user to any page after he has submitted the data to that site? 用户将数据提交到该站点后,是否可以将其重定向到任何页面? I have checked a number of suggestions but not sucess at this point. 我已经检查了一些建议,但目前还没有成功。 thanks in advance 提前致谢

When you submit a form, there will be an automatic browser redirection to the URL you specified in the action attribute of your form. 提交表单时,浏览器会自动重定向到您在表单的action属性中指定的URL。 Here is a minimal example: 这是一个最小的示例:

 <form action="http://stackoverflow.com"> <input type="text"> <input type="submit" value="Submit"> </form> 

Now, if you want to code a form properly, you should follow the Post/Redirect/Get pattern. 现在,如果要正确编码表单,则应遵循“ 发布/重定向/获取”模式。 Ajax is a viable solution for what you want to do: Ajax是您想要做的可行的解决方案:

(function () {
  // Dummy submit handler
  function handler() {
    var xhr = new XMLHttpRequest(),
        url = "action.php",
        params = "foo=Foo&bar=Bar";

    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xhr.onreadystatechange = function() {
      if(xhr.readyState == 4 && xhr.status == 200) {
        console.log(xhr.responseText);
        location.href = "http://stackoverflow.com";
      }
    }

    xhr.send(params);
  }
})();

In your registar.php file, add header('Location: https://www.example.com/example.html'); 在您的registar.php文件中,添加header('Location: https://www.example.com/example.html');

This isn't necessarily JavaScript, but it's probably the most efficient method. 这不一定是JavaScript,但它可能是最有效的方法。

If you do not have to wait for the answer, you can use javascript (jquery if you want and can) for this: 如果您不必等待答案,可以为此使用javascript(如果需要,可以使用jquery):

$("#entrar2").click(function(){
    $(location).href(link);
});

Your submission will cancel the redirect. 您的提交将取消重定向。

<form name="form1" id="form1" method="post" onsubmit="return redirect()">  
   <input type="submit" class="button4" name="order" id="order" value="Place Order" >
</form>

<script>
    function redirect() {
        window.location.replace("login.php");
        return false;
    }
</script>

OR 要么

document.getElementById("formId").onsubmit=function() {
   window.location.replace("https://jsfiddle.net/");
   return false;
}    

You have to send your data to other website using curl before form submitted.Where you can process your data or store it . 在提交表单之前,您必须使用curl将数据发送到其他网站。您可以在此处处理或存储数据。 And after successful response from other page you can redirect user to any page 从其他页面成功响应后,您可以将用户重定向到任何页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM