POST按钮值不与后端一起使用

时间:2018-10-29 20:01:17

标签: php html

所以我有一个应该在后端传递按钮值的脚本

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $monday_hours = $_POST['monday_hours'];
   echo $monday_hours;                                                
}
?>

这是html代码。

<div class = "mon-btn-group">
  <form method="post"> 
    <button type = "button" name = "monday_hours" value = "1_hour">1</button>
    <button type = "button" name = "monday_hours" value = "2_hours">2</button>
    <button type = "button" name = "monday_hours" value = "3_hours">3</button>
  </form>
</div>

所以我的问题是不更改类型,如果这组按钮值都具有相同的名称(如单选按钮或复选框),是否有可能在后端捕获它们?

如果我删除type =“ button”,它会回显该值,但是我不希望那样,因为我读到按钮已作为默认行为提交。

  

Send Bootstrap Button-Group value in a form with Get or Post

编辑:Nevermind找到了这篇文章,谢谢大家,这是我第一次发布。

1 个答案:

答案 0 :(得分:0)

您的按钮应具有唯一的名称。还应该将它们包装成将方法设置为POST的形式。

<button type = "button" id = "m1" name = "monday_hours_1" value = "1_hour">1</button>
<button type = "button" id = "m2" name = "monday_hours_2" value = "2_hours">2</button>
<button type = "button" id = "m3" name = "monday_hours_3" value = "3_hours">3</button>