Make page to tell browser not to cache/preserve input values

queen3 picture queen3 · Apr 23, 2010 · Viewed 178.2k times · Source

Most browsers cache form input values. So when the user refreshes a page, the inputs have the same values.

Here's my problem. When a user clicks Save, the server validates POSTed data (e.g. checked products), and if not valid, sends it back to the browser. However, as stated above, even if the server clears selection for some values, they may still be selected because of the browser cache!

My data has invisible (until parent item selected) checkboxes, so the user may be even not aware that some previous value is still selected, until clicking Save again and gets an error message - even though the user thinks it's not. Which is irritating.

This can be resolved by doing Ctrl + F5, but it's not even a solution. Is there an automatic/programmatic way to tell browser not to cache form input data on some form/page?

Answer

DisgruntledGoat picture DisgruntledGoat · Apr 23, 2010

Are you explicitly setting the values as blank? For example:

<input type="text" name="textfield" value="">

That should stop browsers putting data in where it shouldn't. Alternatively, you can add the autocomplete attribute to the form tag:

<form autocomplete="off" ...></form>