How to prevent form fields from repopulating after clicking the back button?

后端 未结 3 1244
一整个雨季
一整个雨季 2020-12-18 11:00

I have a simple form which has four fields named firstName, lastName, address and phone number.

After a user fills this form and clicks the submit button, if everyt

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-18 11:27

    Repopulating form fields is a good thing, stop trying to break it.

    If what you actually want is to prevent duplicate submissions, send a unique id (e.g. UUID) along with the form and keep track of the ones you've received recently (how many to keep track of depends on your application).

    If you receive a duplicate you can either ignore it (and display appropriate message), or go a step further: check whether the received data has already been submitted or whether it's an attempt to change the previous submission (i.e. fixing a typo), or to create a new record (maybe firstname and phone were changed), or prompt the user to choose, or whatever.

提交回复
热议问题