I have this thymleaf page:
<form method="post" action="#" th:object="${userData}" >
<table>
<tr>
<td><label th:text="#{manageusers.firstnamelabel}">Surname</label></td>
<td><input required="required" type="text" th:field="*{Firstname}" /></td>
</tr>
<tr>
<td><label th:text="#{manageusers.lastnamelabel}">Lastname</label></td>
<td><input required="required" type="text" th:field="*{Lastname}" /></td>
</tr>
</table>
<input type="submit" name="back" value="Back"/>
<input type="submit" name="confirm" value="Confirm"/>
</form>
What I want is different action (ie. different page controller action) based on submit button clicked. Is there a way I can handle this in thymeleaf or spring boot (In my controller class)?
You don't want to change the form action, you want different handler methods depending on the button pressed.
back:
@RequestMapping( value="/your-url", method=POST, params={"back"} )
confirm:
@RequestMapping( value="/your-url", method=POST, params={"confirm"} )
Personally I name my buttons btnX, so as to differentiate them from model attribute field names.
Also, use <button type=submit> instead of <input type=submit> as this lets you specify name, text and value.
While we're at it, don't use html tables for layouts. Try Bootstrap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With