5

I have:

  • page1: submits a form

  • page2: validates it and and returns a page

Now when I click the back button, it does not go to page-1 instead it comes with a "Confirm form resubmission" window.

How do I prevent this? Based on this answer, I see this as a recommended approach:

This is a common technique on forums. Form on Page1 posts the data to Page2, Page2 processes the data and does what needs to be done, and then it does a HTTP redirect on itself. This way the last "action" the browser remembers is a simple GET on page2, so the form is not being resubmitted upon F5.

But I'm confused. Where should I append my redirects? My page2 view looks like this:

@app.route('/StartPage',method='POST')
def test():
    username = request.forms.get('username')
    password = request.forms.get('password')
    return template('StartPage',search_string=search_string,\
                    username=username, \
                    session_id=ses_id)
Basj
  • 41,386
  • 99
  • 383
  • 673
user1050619
  • 19,822
  • 85
  • 237
  • 413

1 Answers1

3

To follow the POST-Redirect-GET pattern, your POST route shouldn't return a template.

  • If it can successfully process the form data, it should afterwards redirect to some sort of success/next page.

  • If there's a validation error, it should redirect back to the form, perhaps with the error details included in a query string.

daaawx
  • 3,273
  • 2
  • 17
  • 16
nkorth
  • 1,684
  • 1
  • 12
  • 28