8.1.11 Handling Duplicate Form Submissions 6.0.0

(Quick Reference) # 8.1.11 Handling Duplicate Form Submissions Version: 6.0.0 ## 8.1.11 Handling Duplicate Form Submissions Grails has built-in support for handling duplicate form submissions using the "Synchronizer Token Pattern". To get started you define a token on the form tag:
    <g:form useToken="true" ...>
Then in your controller code you can use the withForm method to handle valid and invalid requests:
    withForm {
       // good request
    }.invalidToken {
       // bad request
    }
If you only provide the withForm method and not the chained `invalidToken` method then by default Grails will store the invalid token in a `flash.invalidToken` variable and redirect the request back to the original page. This can then be checked in the view:
    <g:if test="${flash.invalidToken}">
      Don't click the button twice!
    </g:if>
| The withForm tag makes use of the session and hence requires session affinity or clustered sessions if used in a cluster.
| Quick Reference (hide)