简体   繁体   English

提交按钮重定向多个页面

[英]Submit button redirect multiple page

Is there possible to redict multiple page after submit button?提交按钮后是否可以修改多个页面? For example, user click 'Submit' then it will go to page1.php (same tab) and page2.php (another tab).例如,用户单击“提交”,然后它将 go 到 page1.php(相同选项卡)和 page2.php(另一个选项卡)。

<form role="form" method="post" action="">
<button type="submit" name="submit" >Submit</button>
</form>

if(isset($_POST['submit'])){
header("location:page1.php");
header("location:page2.php");
}

The simple answer is no.简单回答是不。 Only the page that submitted the request can receive a redirect response.只有提交请求的页面才能收到重定向响应。 The more complicated answer is if the first page opened the second page it can exercise some control over it via javascript.更复杂的答案是,如果第一页打开第二页,它可以通过 javascript 对其进行一些控制。 You could also use a websocket based mechanism to cause a page to reload similar to how react dev server works.您还可以使用基于 websocket 的机制来重新加载页面,类似于 react 开发服务器的工作方式。

You can use a combination of php and javascript.您可以使用 php 和 javascript 的组合。

Add a javascript function to the onsubmit of the form:在表单的 onsubmit 中添加 javascript function:

var win = window.open(url, '_blank');

then, in your php, use your code to check for $_POST var and use:然后,在您的 php 中,使用您的代码检查 $_POST var 并使用:

header('Location: url');

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

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