如何用GET发送表单的一部分,用POST发送另一部分


How to send a part of the form with GET, another with POST?

我正在回显一个表单,该表单使用GET方法通过多个输入type="hidden"发送材料。像这样:

echo '
<form action="somewhere.php" method="GET" name="whatever" id="whatever">
   <input type="hidden" name="get_method" value=" . '$foo' . ">
   <input type="hidden" name="want_to_send_with_post" value=" . '$my_post' . ">
</form>
';

这很好,但是我如何将其中一个输入类型作为POST发送,因为它是确定方法的表单?有没有一种方法可以让单个输入类型覆盖表单方法?我知道输入按钮可以覆盖表单方法(请参见此处(,但这是在创建一个单独的实体。我想同时发送GET和Post。

原因:我想用Get发送类别名称,用POST发送文本消息。

是的,你可以!在您要访问的URL中指定GET数据。

(当用户输入数据时,我会用javascript编辑GET信息(

<input type="text" id="get"> <!--user types get stuff here-->
<form action="somewhere.php?get=something" method="POST" id="form">
    <input type="hidden" name="post" value="<?= $mypost ?>" />
</form>

使用JS更改GET操作

var form = doc.getId("form")
var get = doc.getId("get").onkeyup = updateLoc;
function updateLoc() {
    form.action = "somewhere.php?get=" + get.value;
}

然后PHP可以分别处理$_POST["post"]$_GET["get"]