如何使用PHP获取链接变量的输入字段值

时间:2017-12-19 18:56:39

标签: php

我找到了这个话题:

How to get input field value using PHP

但它对我没有帮助。我没有任何形式:

echo '<input required  type = "number" name = "db" value="1" /><br>';

我希望这个输入类型值存储在一个变量中,如果我点击一个链接它也应该发送这个复选框数据并打开带有这些值的href。

喜欢?buy =#product_id&amp; quantity =#insert_value_here

现在它只发送product_id,数量值为空。

1 个答案:

答案 0 :(得分:1)

下面显示的表单将提交到网址,它会添加buy =#product_id&amp; quantity = #insert_value_here,以便您可以使用php访问这些变量。 $ _GET [&#39;购买&#39;]和$ _GET [&#39;数量&#39;]

使用SO片段提交后,这是在javascript控制台中: enter image description here

您需要进行一些验证,以确保设置值并确保它们是正确的信息类型。此外,post会比get更好,并且使用nonce将有助于防止不必要的多次提交......

&#13;
&#13;
<form action="http://www.google.com" method="get" name="add-to-cart">
  <select name="buy">
    <option value="1">Product One</option>
    <option value="2">Product Two</option>
    <option value="3">Product Three</option>
  </select>
  <input type="number" name="quantity" max="10" min="0" step="1" required />
  <input type="submit" value="Submit" />
</form>
&#13;
&#13;
&#13;