如何使表单提交按钮添加到表单方法=“获取”网址


How can you make a form submit button add to a form method="Get" url?

如何将"获取请求"添加到表单按钮? 例如,如果您单击[Landscape]按钮,如何使其转到print.php?Landscape

 <form action="print.php" method="get">
   <input type="submit" class="btn btn-default" formaction="print.php?&type=Landscape" name="Landscape" value="Landscape"/>
   <input type="submit" class="btn btn-default" formaction="print.php?&type=Portrait" name="Portrait" value="Portrait"/>
 </form>

打印.php

 <?PHP
 $Landscape= $_REQUEST['Landscape'];
  echo $Landscape;
 ?>

当您提交表单时,表单数据将表示为一组name=value对。

在 HTML 中,无法通过提交表单来生成没有=valuename

由于提交按钮具有名称和值,因此您已经拥有的代码将生成:

print.php?Landscape=Landscape

。这应该足以满足所有实际目的。


也就是说,由于您没有其他控件,因此您可以(并且可能应该)只使用链接。

 <a href="print.php?Landscape" class="btn btn-default">Landscape</a>

名称和值与 method="get" 相结合将产生 print.php?&Landscape=Landscape 。 这似乎是你要的。

<form action="print.php" method="get">
<input type="submit" class="btn btn-default" name="Landscape" value="Landscape"/>
<input type="submit" class="btn btn-default" name="Portrait" value="Portrait"/>
</form>