By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

MVC form submission POST-Redirect-GET problem

dlite922
Expert 100+
P: 1,584
Guys, my brains fried and is not working. need your help.

I've got an Entity let's call it "Item",

in my Item controller I have the following actions

/item/index
:: Views the item, submits POST to /save

/item/update
:: Validates and saves Item fields to DB and redirects back to /index

/item/create
:: Creates a blank form to add a new Item, submits to itself, validates, saves and redirects to /index to view it.

/item/delete
:: Confirms delete, deletes from database if yes, and redirect back to /list/


My question is how do you guys prevent resubmission of the data to the DB, if the user clicks the back button?

303 Redirect? like this: http://en.wikipedia.org/wiki/Post/Redirect/Get

Is there anyway for header("Location..") to wipe the history and replace the page just like javascript window.location.replace() ?

Thanks,

Dan
Dec 17 '11 #1
Share this Question
Share on Google+
5 Replies


zorgi
Expert 100+
P: 431
Could you:
  1. store uniqid() into the session and same id into the hidden field on your form
  2. when submitting check if hidden field and session hold the same value
  3. if values correspond submit was valid -> destroy session to prevent further submits using same uniqid
  4. if values do not correspond than its a case of double submit
Dec 18 '11 #2

dlite922
Expert 100+
P: 1,584
I'm going to try to stay away from session if possible and look for a minimal maintenance/ elegant solution. Perhaps session is the only way, however I haven't quit yet...

Dan
Dec 19 '11 #3

zorgi
Expert 100+
P: 431
I had similar issue recently and wanted to stay away from session just like you are trying now. I gave up on the end and did session thing. My problem was slightly different. I wanted to prevent quick double click submit. Are you using ZF or some other framework.
Dec 19 '11 #4

dlite922
Expert 100+
P: 1,584
I'm using a self-made bare-bones framework. (mod-rewrite and call_user_func() basically)
Dec 20 '11 #5

zorgi
Expert 100+
P: 431
Oh well... Reson I asked is that I have Zend_Form ready made solution to this problem.
Dec 20 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.