views:

806

answers:

1

Most browsers cache form values, so when the user navigates to another page and then presses the back button doesn't have to start over again.

With the jquery form plugin this also happens after the form has been submitted successfully.

The following scenario:

  1. user submits form

  2. message is shown that submission was successful and form is cleared

  3. user navigates to some other page

  4. user presses the back button

  5. page is restored to the state before the form was submitted.

Calling resetForm() after submit only brings back the initial form values but doesn't solve the cache issue.

$(document).ready(function(){
    $('form').ajaxForm({
        success: function(responseText, statusText){
            displayMessage('form successful');
            $('form').resetForm();
        }
    });
});

Calling resetForm() when the page is loaded solves the cache issue but breaks the expected browser behavior when navigating between pages:

$(document).ready(function(){
    $('form').ajaxForm().resetForm();
});

Is there a way to clear the cache after a successful submit?

+1  A: 

I'm not that much into JQuery but the storing of form values can be generally switched off using

autocomplete='off'

source for example here

As far as I know, there is no other cross-browser way of influencing what values the browser stores in its cache. I think it is unlikely to get access to this stuff programmatically because of the complex security implications this would bring along.

Pekka