Connecting a Controller to a View

In general, the problem is that my controller understands which button was pressed, the buttons are formed in the View in a loop, lines with questions are pulled from the database and under each question a form and a button for answering, and so my controller cannot determine which button was clicked if not name each button by question id, but I don’t think that’s the right way. How to solve this issue?

Answer 1, authority 100%

Change the controller so that for each responsea form with a button is generated:

<form action="..." method="post" >
  <input type="hidden" name="answer_id" value="..." />
  <input type="submit" value="" />

The selected answer can then be identified by the unique $_POST[‘answer_id’].

Answer 2

Usually, the choice is made not with buttons, but with radio, if you want 5 buttons – make 5 forms and specify the parameters that are convenient for you.

Answer 3

You can give all the buttons the same name, but the values ​​are different, as an option. Well, then

buttonvalue = request.getparameter(buttonName);
if (buttonValue == "value") {...}