Page 1 of 1

using header(location to avoid resubmission of form data

Posted: Tue Nov 25, 2008 2:34 pm
by sparrrow
So I have a shopping cart with all code contained within the one page. It has functions for shopping cart actions of add, update, delete that update the db table based on the user action. The type of scenario I'm trying to tackle is if a user adds something to their cart then refreshes, it adds the item again. etc etc typical form resubmission issue.

So I had an idea, tested it, and it appears to work. But I'm concerned that I haven't seen this solution on these boards or google anywhere so maybe there's a problem that I'm not seeing that could occur by doing it this way.

Basically, user submits change to shopping cart -> Shopping cart add, delete, or update function is called. At the end of each function, I just added header('Location: cart.php'); So page loads, cart is updated, then header location is changed to cart.php with no POST data, so user can freely refresh, use back button, whatever they want. What am I overlooking? This seems TOO easy...

Re: using header(location to avoid resubmission of form data

Posted: Tue Nov 25, 2008 4:22 pm
by veridicus
That's a great solution. On some sites I do a redirect to a list view page after a create / edit / delete from a record's detail page. It solves the refresh/repost problem and often helps with usability.

Re: using header(location to avoid resubmission of form data

Posted: Tue Nov 25, 2008 5:01 pm
by Jade
I've seen that done a lot with shopping carts. Especially with payment pages because you don't want someone paying twice -- although they ALWAYS find a way :banghead: