Search code examples
grailsgrails-2.0grails-controller

How to prevent a page from resubmitting? in grails 2.2.0


When once form is submitted successfully....

but When I click on "BACK" button and trying submit same form its gives me an error enter image description here

Source:

<g:form action="addData" name="addValues" controller="emp" method="Post">
</g:form>

Controller Source:-

def editProfile (Long id,Long version){
        withForm {
        // code
            }.invalidToken {
            response.status = 405

        }
    }

Solution

  • Its hard to infer the cause of the error with what you have posted. However, you asked about how to prevent a page from resubmitting in Grails. Take a look at documentation. Grails has a build in support for that. Basically you define a form with a token and using withForm you will check if the token still is valid or not.

    <g:form useToken="true" ...>
    

    /

    withForm {
       // good request
    }.invalidToken {
       // bad request
    }