I have following problem: I have two buttons accept and decline. In my Controller-Class i want to know, which button were clicked. i solved this in a way, which is bad i think. Each button got his own form, so that i can see which button was triggered.
<form method="post" action="save">
<input type="hidden" name="accept" th:value="true" />
<button type="submit" name="accepted" id="modalAcceptTrigger"
class="btn btn-lg myBtn_accept" title="Auftrag annehmen">
Annehmen
</button>
</form>
<form method="post" action="save">
<input type="hidden" name="decline" th:value="false" />
<button type="submit" name="declined" id="modalDeclineTrigger"
class="btn btn-lg myBtn_decline" title="Auftrag abgelehnt">
Ablehnen
</button>
</form>
In my class i get the hidden input field and know which button was pressed.
@PostMapping("/save")
public String saveJob(@RequestParam(value = "accept") Boolean accept) {
if (accept) {
...
} else {
...
}
}
My question is now: How can i make only one form and get the triggered button in my java class? Does anybody know and can help me?