1

I need to find a way to refresh a page without including user form details - this is messing up my shopping cart system (number of items keeps going up on refresh). When I navigate away from the shop page then back the problem is gone. Only when I add an item to cart THEN click refresh the number of items start going up - so the form info is being stored whilst still on the shop page.

Is there a way with say jquery to clear/reset the form - like what happens when I navigate away and back to the page.

My site is www.flytraptestsite.com using Woocommerce (wordpress) - thanks.

braX
  • 11,506
  • 5
  • 20
  • 33
user1684099
  • 139
  • 1
  • 3
  • 10

2 Answers2

0

I would guess the issue arises when the users browsers submits a form an extra time upon page reload. One possible solution might be not to use window.location.reload() but instead just set the location manually, like so: window.location.href = some_url.

You might also work around this issue by doing a HTTP redirect once a form has been successfully be submitted. That way, the page you are later reloading is the page redirected to, and not the page initially receiving the form submission (and thus potentially still holding on to the post data).

Simon
  • 3,667
  • 1
  • 35
  • 49
  • Thanks just saw your answer and the page was reloading with a get variable so I just specified the main address thanks! – user1684099 Oct 23 '12 at 09:53
  • Yeah, I presumed post variables, but naturally you'll get the same issue with get variables. Glad I could help! – Simon Oct 23 '12 at 09:59
0
$('#form_id').each(function() {
    this.reset();
});

Or create a jquery form reset method:

jQuery.fn.reset = function () {
    $(this).each (function() {
        this.reset();
    });
}

$("#form_id").reset();

Or maybe just:

document.getElementById('form_id').reset();
Stefan
  • 3,850
  • 2
  • 26
  • 39
  • Thanks for this - my problem I just realized is there is a get variable in the address bar - I just need to close my iframe and redirect to the main shop page (instead of the one with the get var) - so currently I'm using "parent.location.reload(true);" - what is the jquery to load a specific page in the parent window? Thanks for your help. – user1684099 Oct 23 '12 at 09:34