Prevent user to use back button with warning or disable any insert

前端 未结 2 1089
-上瘾入骨i
-上瘾入骨i 2020-12-20 10:25

I have a form in page1.php which directs to page2.php from where the data from the form in page1.php is inserted into database. after

2条回答
  •  旧时难觅i
    2020-12-20 10:44

    You should not display your message on page2.php.

    Instead :

    • page2.php should deal with the data
    • when the data has been saved, page2.php should redirect to confirmation.php
    • And it's only confirmation.php which would display the message.


    For more informations, take a look at the Post/Redirect/Get pattern.


    Edit after the comment : but note that, in any case, you will never be able to prevent the user from re-submitting a form, if he really wants to...

    The only solution you'll have is, when a form is submitted, to check in your database if the currently submitted data already exists -- and if it does, refuse to insert it again.

    Of course, if the suer changes even a single letter in his input, it won't be the same data anymore...

提交回复
热议问题