John R
John R

Reputation: 43

How to prevent browser from refilling form data when navigating back

I have a php form that submits data to a database. When the form has been successfully filled out and the data submitted, the form clears because of the page refresh. When the user hits the back button on the browser, the data comes back.

Is there a php function that will prevent the caching of this data?

Upvotes: 4

Views: 1681

Answers (2)

Jon Hanna
Jon Hanna

Reputation: 113282

There isn't a reliable method, because the behaviour on back varies between browsers. Moreover, if someone has gone back through history, and you change what's happening, you are changing history. The metaphysical "woah!" of that aside, it's not a great idea.

What problem does this cause, apart from issues of from-resubmission? If form-resubmission is a problem then you need to deal with it in the case of a quick double-click on submit too anwyay. Include a hidden nonce value (UUIDs are good), store the nonce with your record of whatever it is the form does, and reject repeated nonces.

Upvotes: 1

ggarber
ggarber

Reputation: 8360

autocomplete="off" in the input fields of your forms?

Upvotes: 3

Related Questions