【问题标题】:get the value of input element and display it in php page获取输入元素的值并在php页面中显示
【发布时间】:2014-09-10 16:20:33
【问题描述】:

我有这个表格

<form method="post" action="file.php">
<input type="button" name="one" value="1">
</input>
<input type="button" name="two" value="2">
</input>
<input type="submit">
</input>
</form>

如何获取此 INPUT 的 VALUE 并在 php 页面中显示此值?我尝试过这种方式,但它不起作用。我该怎么做?

$_POST[nameOfInput]

【问题讨论】:

  • 您的输入没有名称。你期待什么?
  • 我忘了在这个问题中添加名称,但在我的网页中有;)

标签: php html forms input


【解决方案1】:

您不能发送按钮的值。使用单选字段,例如:

<input type="radio" name="choice" value="1" />
<input type="radio" name="choice" value="2" />

或者你也可以使用下拉菜单:

<select name="choice">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
</select>

然后在 PHP 中:

echo $_POST['choice']; // possible results: NULL/1/2

【讨论】:

  • 尝试使用以下格式(在我的回答中)而不是&lt;input&gt;&lt;/input&gt;
  • 因为这些是按钮。改为使用输入 type="radio" 来获取值。
  • 只有单选按钮才有可能选择这个提示?在这种情况下,你是我最好的答案:D
  • 你也可以使用下拉菜单(select标签)
猜你喜欢
  • 1970-01-01
  • 2011-12-10
  • 1970-01-01
  • 2017-03-27
  • 1970-01-01
  • 2012-09-14
  • 2022-09-29
  • 1970-01-01
  • 2020-09-12
相关资源
最近更新 更多