I have a form with bunch of submit inputs, each input has a unique name, now I want to check in the controller which input is being clicked.
The Form
<input type="submit" name="button_1" value="1">
<input type="submit" name="button_2" value="2">
<input type="submit" name="button_3" value="3">
<!-- and more submit inputs -->
in the controller, I use if else now to check which input is being clicked, for example I can use this
if ($request->input('button_1'))
{$message = '1';}
elseif ($request->input('button_2'))
{$message = '2';}
elseif ($request->input('button_3'))
{$message = '3';}
// ...
or I can use this
if ($request->has('button_1')) {$message = '1';}
elseif ($request->has('button_2')) {$message = '2';}
elseif ($request->has('button_3')) {$message = '3';}
// ...
is there a better way to check which submit input is being clicked, like a switch method for example, because that will make the writing logic much simpler and cleaner but I couldn't figure it out.
Aucun commentaire:
Enregistrer un commentaire