Saturday, January 17, 2009

How to make firefox not to remember entered information into the form

Solution is really shorter than title of this post.


Add a random number to form name, so it will look like this:

<form name="review-788014185" method="post" action="#" id="reviewForm">

Random number is generated easily in most of programming languages. In PHP it would look like this:

<form name="review-<?=rand()?>" method="post" action="#" id="reviewForm">


I should say why did I bring this. I am working on a form where reviews could be submitted only with help of javascript. I know that it's not the wisest solution due to it's lack of accessibility and problems with usability, but I believe that there wouldn't be many visually impaired people visiting this particular site due to it's topic also I know that most of people have JS turned on.
So to make story short Java Script handles all submission process it doesn't change status of form (submitted/not) for browser. Firefox by default remembers what was entered into the form if you happen to simply refresh a page with F5 or Ctrl+R. See the problem? Although all data was passed to server browser is not aware of that it still thinks you're editing form so it saves all data for you. So i had to prevent it somehow. So I had to trick it and my trick was in having different name for the form on every reload.


Later I'd change it to a more sophisticated solution where JS also leaves a cookie with form ID so on every reload I would name form with the same name until it was submitted. On the event of submission I would replace this cookie with another one which says this user already left a review so I don't expect another one from them for another hour. Knowing this I wouldn't show a form. Simple.

1 comment:

  1. This method fails to work -- tested with FF3 / Linux.


Please be moderate saying your thoughts and do not offend others.