<g:form useToken="true" ...>
8.1.11 Handling Duplicate Form Submissions
Version: 5.0.2
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:
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>