简体   繁体   中英

Hitting browser “Back” button causing details to save

I've had a report from a user that whenever they go to edit their profile details, if they hit "Back" on their browser, any changes they may have made are saved, when they should only be saved by them clicking the "Save" button in the page.

What possible reasons are there for this happening, and how can I prevent it?

Sound like a form resubmission issue. Have a look here and see if that points you in the right direction

This sort of thing can also happen if the user double-clicks on the 'submit' button and triggers two form submissions.

The solution to it is to have a field in the form which is a unique reference ID which is generated each time the form is loaded.

When the form is submitted, your program should make a note that this ID has been used (maybe store this in the user's session), and reject any subsequent attempts to post a form with the same ID.

There are many ways of implementing this, so I won't give you a code example, but it should be fairly straightforward.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM