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

问题描述 投票:-1回答:1

我找到了这个话题:

How to get input field value using PHP

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

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

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

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

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

php
1个回答
1
投票

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

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

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

<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>
© www.soinside.com 2019 - 2024. All rights reserved.