Php 如何将表单提交按钮添加到表单方法中=";获得;网址?
如何将Get请求添加到表单按钮?例如,如果单击Php 如何将表单提交按钮添加到表单方法中=";获得;网址?,php,forms,Php,Forms,如何将Get请求添加到表单按钮?例如,如果单击[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"/> <
[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>
print.php
<?PHP
$Landscape= $_REQUEST['Landscape'];
echo $Landscape;
?>
提交表单时,表单数据将表示为一组
name=value
对
在HTML中,无法通过提交表单来生成没有=值的名称
由于“提交”按钮具有名称和值,因此您已有的代码将生成:
print.php?Landscape=Landscape
…这对于所有实际目的来说都是足够的
这就是说,因为您没有其他控件,所以您可以(也可能应该)只使用链接
<a href="print.php?Landscape" class="btn btn-default">Landscape</a>
与method=“get”
组合的名称和值将产生print.php?&scape=scape
。这似乎是你想要的
<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>
所以你可以做一个?@Sol-No。使用链接而不是按钮。它如何拉入表单数据?或者它不能?@Sol-a链接不会提交任何表单数据。这就是为什么我在前面建议您使用带有“因为您没有其他控件”语句的链接。如果这是因为你把你的例子删减得太多而没有展示出来,那么这个陈述显然不适用,你应该只关注答案的前半部分。@Sol-No。正如我所说,您已使用的提交按钮具有名称和值,因此用于提交表单的按钮将显示在已提交的数据中。只是不是你最初要求的格式。而且,由于您现在希望将其命名为type,而不是您现在要求的名称。如果用于提交表单,您在问题中输入的PHP将找到横向按钮。