Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何区分链接到同一.php页面的两个相等输入_Php_Html - Fatal编程技术网

如何区分链接到同一.php页面的两个相等输入

如何区分链接到同一.php页面的两个相等输入,php,html,Php,Html,我可能很笨,但我读了这里所有关于类似论点的问题,但我无论如何都无法解决我的问题(我知道这是一个愚蠢的简单问题)。 在页面city.php中有两个相同的表单,其中两个相同的表单链接到同一个页面overview.php;像这样: <form method="get" action="overview.php"> <input type="submit" value="Gallery"> </form> ... <form method="get" act

我可能很笨,但我读了这里所有关于类似论点的问题,但我无论如何都无法解决我的问题(我知道这是一个愚蠢的简单问题)。 在页面city.php中有两个相同的表单,其中两个相同的表单链接到同一个页面overview.php;像这样:

<form method="get" action="overview.php">
  <input type="submit" value="Gallery">
</form>
...
<form method="get" action="overview.php">
  <input type="submit" value="Gallery">
</form>
 <?php
     $redirectTo $_POST["redirectTo"];

     if($redirectTo == 'Type1'){
         ?>
              <html>Make all you want</html>
         <?php
     }
     if($redirectTo == 'Type1'){
         ?>
               <html>Make all you want</html>
         <?php
     }
 ?>
提前谢谢

2种方式:

您可以调整窗体的操作:

action="overview.php?id=1"
或者你可以这样做:

<form method="get" action="overview.php">
  <input type="hidden" name="id" value="1" />
  <input type="submit" value="Gallery" />
</form>

因为您想使用链接,所以可以通过设置以下行来实现:

您应该这样做: 这是“Form1.php”


去
去
在“overview.php”中,您应该有如下内容:

<form method="get" action="overview.php">
  <input type="submit" value="Gallery">
</form>
...
<form method="get" action="overview.php">
  <input type="submit" value="Gallery">
</form>
 <?php
     $redirectTo $_POST["redirectTo"];

     if($redirectTo == 'Type1'){
         ?>
              <html>Make all you want</html>
         <?php
     }
     if($redirectTo == 'Type1'){
         ?>
               <html>Make all you want</html>
         <?php
     }
 ?>

随心所欲
随心所欲
将名称改为id

<form method="get" action="overview.php">
  <input type="submit" name="1" value="Gallery1">
</form>
...
<form method="get" action="overview.php">
  <input type="submit" name="2" value="Gallery2">
</form>

...

不可能。只能提交一个
,因此不提交另一个表单中的值。和
id
未提交。只有
name
value
。您需要传递一些get参数,然后在此基础上,理想地更新其他内容,如cookie或会话项以记住您的状态。如果表单是Method=“GET”,则有一个名为:value的隐藏字段。或者,您可以将其附加到操作。。。因为它是一个get,但是它不被推荐。我喜欢把事情分开并整齐地组织起来。或者只是使用一个链接,适当地设置样式
是的,我认为链接是理想的。我不确定他们是否遗漏了使
表格成为要求的信息。由于他引用了它,并以它为基础提出了他的问题,我觉得答案应该利用它。感谢FallenReapper,type=“hidden”的方法非常有效!史蒂夫发布的链接解决方案也很酷;这是首选而不是隐藏的输入类型,还是仅仅是另一种方式?考虑到我没有任何形式,只是按钮。它们叠加在两个不同的图像上;如果您单击overview.php中的左侧,您将首先看到该图库,否则,如果您按右侧按钮,您将首先看到另一个图库。@brigo如果您试图使用get params引用不同的页面,将使用锚定标记。这是链接到另一个页面的常见方式,因为GET只使用查询字符串,所以很容易连接。表单以某种方式用于处理,而不是从一页转到另一页。如果您正试图处理表单,请按此路线操作。如果您试图四处导航,请使用:
@fallereneaper和Steve Yep,我想我将使用链接解决方案添加这个简单的check in overview.php:
$query\u url=$\u SERVER['query\u STRING';如果($query\u url=='choice=1'){echo'..content X';}elseif($query\u url=='choice=1'){echo'..content Y';}否则{echo'Error';}
以这种方式,我不必执行任何其他检查,即使用户只是将链接粘贴到栏中,而不需要浏览city.php(很抱歉,我试图格式化代码部分,但不知道如何格式化!)
 <?php
     $redirectTo $_POST["redirectTo"];

     if($redirectTo == 'Type1'){
         ?>
              <html>Make all you want</html>
         <?php
     }
     if($redirectTo == 'Type1'){
         ?>
               <html>Make all you want</html>
         <?php
     }
 ?>
<form method="get" action="overview.php">
  <input type="submit" name="1" value="Gallery1">
</form>
...
<form method="get" action="overview.php">
  <input type="submit" name="2" value="Gallery2">
</form>