withForm {
// good request
}.invalidToken {
// bad request
}
withForm
Purpose
Used to handle duplicate form submissions.
Examples
Description
The withForm method requires the use of the useToken attribute in a form
<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
}
Tokens are single-use. A valid token is consumed atomically when withForm validates it, so duplicate concurrent submissions for the same token allow exactly one request to run the valid block. Grails stores token state in the session with a limit of 100 form URL buckets and 100 tokens per URL; after those limits, the oldest bucket or oldest token is discarded and later submission of that form is handled as invalidToken.
See Handling Duplicate Form Submissions for more information.