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

后端 未结 23 1606
醉话见心
醉话见心 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:50

    As others have said, it is not possible to out of using post/redirect/get. But at the same time it is quite easy to do what you want to do server side.

    In your POST page you simply validate the user input but do not act on it, instead you copy it into a SESSION array. You then redirect back to the main submission page again. Your main submission page starts by checking to see if the SESSION array that you are using exists, and if so copy it into a local array and unset it. From there you can act on it.

    This way you only do all your main work once, achieving what you want to do.

提交回复
热议问题