java - Form with multiple action? -


i have 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 want different action (ie. different page controller action) based on submit button clicked. there way can handle in thymeleaf or spring boot (in controller class)?

you don't want change form action, want different handler methods depending on button pressed.

back:

@requestmapping( value="/your-url", method=post, params={"back"} ) 

confirm:

@requestmapping( value="/your-url", method=post, params={"confirm"} ) 

personally name buttons btnx, differentiate them model attribute field names.

also, use <button type=submit> instead of <input type=submit> lets specify name, text , value.

while we're @ it, don't use html tables layouts. try bootstrap.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -