简体   繁体   English

根据用户点击的链接重定向用户

[英]Redirect User based on link they've clicked

Is there a way to specify the header location based on which link the user has clicked? 有没有一种方法可以根据用户单击的链接来指定标题位置? If possible, I'd prefer doing this in PHP. 如果可能的话,我宁愿在PHP中执行此操作。

I'd like to submit forms when the user clicks on any of a few buttons (ie Next, Back, Save, etc.), and they each need to redirect the user differently once the form is submitted. 我想在用户单击几个按钮(例如,“下一步”,“上一步”,“保存”等)中的任何一个时提交表单,并且一旦提交表单,它们各自需要以不同的方式重定向用户。

Example

HTML - form2.html HTML-form2.html

<form name="form2" id="form2" method="post" action="form2-exec.php">        
    <!-- Form Elements -->       
    <a href="form1.php"><input type="submit" value="BACK" /></a>
    <a href="form3.php"><input type="submit" value="SUBMIT" /></a>
</form>

PHP - form2-exec.php PHP-form2-exec.php

// Connect to database
// Insert & ON DUPLICATE KEY UPDATE Statements
header("location: form3.php");

You do not need the anchor tags. 您不需要锚标记。 Can you try something like: 您可以尝试以下方法吗:

<input type="submit" name="whereto" value="BACK" />
<input type="submit" name="whereto" value="SUBMIT" />

PHP - form2-exec.php PHP-form2-exec.php

// Connect to database
// Insert & ON DUPLICATE KEY UPDATE Statements
if ($_GET['whereto'] == 'BACK') {
    header("location: form1.php");
} elseif ($_GET['whereto'] == 'SUBMIT') {
    header("location: form3.php");
}

You can find out more about PHP predefined variables at http://php.net/manual/en/reserved.variables.php 您可以在http://php.net/manual/en/reserved.variables.php上找到有关PHP预定义变量的更多信息。

you can simply use $_POST['submit'] which will contain the value as a value. 您可以简单地使用$_POST['submit'] ,它将包含该value作为值。 Use the name attribute on your submit buttons as well to make it sure. 还要在提交按钮上使用name属性,以确保其属性。

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

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