MVC form submission POST-Redirect-GET problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    MVC form submission POST-Redirect-GET problem

    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.or g/wiki/Post/Redirect/Get

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

    Thanks,

    Dan
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    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

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      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

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        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.

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #5
          I'm using a self-made bare-bones framework. (mod-rewrite and call_user_func( ) basically)

          Comment

          • zorgi
            Recognized Expert Contributor
            • Mar 2008
            • 431

            #6
            Oh well... Reson I asked is that I have Zend_Form ready made solution to this problem.

            Comment

            Working...