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

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

    This form.php sample shows how to use PRG correct (when form is valid or not).

    • It redirects to the same page, only when form is valid and action was performed.
    • Redirection protects form from being resubmitted on page refresh.
    • It uses session to not loose success messages you want to show when form is valid.
    • There are two buttons for testing: "Valid submit", "Invalid submit". Try both and refresh page after that.
    
    

    Hello form



提交回复
热议问题