Avoid duplicate form submitting?
Posted: Mon Dec 07, 2009 7:56 am
Perhaps a common problem, but I'm pondering about the best solution for this:
1. I have a simple shop. If people click on "add product X", they are taken to a new page with a shopping cart (now containing one item X).
2. If they hit F5 or click refresh on the shopping cart page, I don't want *another* X being added to their cart.
3. However, if they go back to the initial shop page, and explicitly click on "add product X" again, then I *do* want another X to be added.
My problem: on the shopping cart page, how do I distinguish between a previous POST request being re-sent due to refresh/F5, and a new one from a real click?
I thought about including a random ID (as hidden field) along with the "add product X" form post, and on the shopping cart I only process items if the ID wasn't already processed before (storing processed IDs in their session or something). However, I think if the customer hits 'back' from the shopping cart page, going back to the first page, most likely they will get the first version from cache, with the same random ID again, which would cause a second "add X" click to be ignored.
What do you think guys??
1. I have a simple shop. If people click on "add product X", they are taken to a new page with a shopping cart (now containing one item X).
2. If they hit F5 or click refresh on the shopping cart page, I don't want *another* X being added to their cart.
3. However, if they go back to the initial shop page, and explicitly click on "add product X" again, then I *do* want another X to be added.
My problem: on the shopping cart page, how do I distinguish between a previous POST request being re-sent due to refresh/F5, and a new one from a real click?
I thought about including a random ID (as hidden field) along with the "add product X" form post, and on the shopping cart I only process items if the ID wasn't already processed before (storing processed IDs in their session or something). However, I think if the customer hits 'back' from the shopping cart page, going back to the first page, most likely they will get the first version from cache, with the same random ID again, which would cause a second "add X" click to be ignored.
What do you think guys??