How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

后端 未结 23 1281
醉话见心
醉话见心 2020-11-22 00:46

I have a simple form that submits text to my SQL table. The problem is that after the user submits the text, they can refresh the page and the data gets submitted again with

23条回答
  •  借酒劲吻你
    2020-11-22 01:53

    This method works for me well, and I think this is the simplest one to do this job.

    The general idea is to redirect the user to some other pages after the form submission, which would stop the form resubmission on page refresh. Still, if you need to hold the user on the same page after the form is submitted, you can do it in multiple ways, but here I am describing the javascript method.

    Javascript Method

    This method is quite easy and blocks the pop up asking for form resubmission on refresh once the form is submitted. Just place this line of javascript code at the footer of your file and see the magic.

提交回复
热议问题