-1

So i have this script that supposed to pass values of buttons on the backend

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

Here is the html code.

<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>

So my question is without changing the type is it possible for this group of buttons values to be caught in the backend if they all have the same name like radio buttons or checkboxes?

It echos the value if i remove the type = "button" but I dont want that since i read that buttons have submit as their default behaviour.

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

EDIT: Nevermind found this post, thanks guys sorry, its my first time posting.

1 Answers1

0

Your buttons should have unique names. They should also be wrapped in a form with the method set to 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>