Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

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

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 everything goes fine, I am redirecting that user to a success page.

But on clicking the browser back button from the success page the form field values are repopulating on the form. How can I prevent this from happening?

I have already tried this code:

<cfheader name="cache-control"  value="no-cache, no-store, must-revalidate">
<cfheader name="pragma" value="no-cache">
<cfheader name="expires" value="#getHttpTimeString(now()-1)#">

But it is not working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...