[英]Redirect to a php page based on submit button clicked
I have two submit buttons in a php page. 我在php页面中有两个提交按钮。 Based on the submit button clicked, I wish to redirect user to different php page.
基于单击的提交按钮,我希望将用户重定向到其他php页面。 How that can be done?
那怎么办呢?
<form>
<input type="submit" value="Go To Page1.php">
<input type="submit" value="Go To Page2.php">
</form>
Assuming you don't have any shared input boxes, you can just do something like this, or use simple links. 假设您没有任何共享的输入框,则可以执行类似的操作或使用简单的链接。
<form action="http://example.org/Page1.php">
<input type="submit" value="Go To Page1.php">
</form>
<form action="http://example.org/Page2.php">
<input type="submit" value="Go To Page2.php">
</form>
If you have additional input elements, I suggest looking into this solution . 如果您还有其他输入元素,建议您研究此解决方案 。 Relevant code sample:
相关代码示例:
<input type="submit" name="submit1" value="submit1" onclick="javascript: form.action='test1.php';" />
You don't need a form for this, neither input fields. 您不需要表格,也不需要输入字段。 Use
<a>
tags instead. 请使用
<a>
标记。 You can style them with CSS to look like a button if you want that. 如果需要,可以使用CSS设置样式,使其看起来像一个按钮。
Just use a set of a
tags inside the form
: 只需使用一组的
a
内部标签form
:
<form>
<!-- Other Inputs -->
<div id="redirects">
<a href="Page1.php">Go to page 1</a>
<a href="Page2.php">Go to page 2</a>
</div>
</form>
If you need to send certain information along with your redirect, keep your current form and have a condition at the top of your file: 如果您需要发送某些信息以及重定向,请保留当前表单,并在文件顶部添加一个条件:
<?php
// You will need to send the $_POST data along with the redirect
if(isset($_POST['submit1']))
header('Location: page1.php');
else if(isset($_POST['submit2']))
header('Location: page2.php');
// Continue with the page...
?>
To send the $_POST
vars along with the redirect, check this other SO post . 要将
$_POST
变量与重定向一起发送,请检查其他SO post 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.