in reply to (CGI) Prevent a reload from resubmitting a form

I don't quite see why you want to prevent the user from resubmitting a form in the first place. Maybe you want to ensure that some operation is only carried out once during the session, but that is something different.

If the underlying problem really is that you carry out some operation, that should be carried out just once, use a server side transaction mechanism to ensure that two concurrent requests won't be able to carry out the operation at the same time, and some mechanism to skip the operation on subsequent requests.

By doing it this way, your web application will be more user friendly by not punishing the user for reloading the page.

  • Comment on Re: (CGI) Prevent a reload from resubmitting a form

Replies are listed 'Best First'.
Re^2: (CGI) Prevent a reload from resubmitting a form
by fmk (Acolyte) on Jun 27, 2009 at 13:03 UTC
    The problem is that, if somebody hits F5 / Strg+R in the Browser, the Data will be send again and also submitted again into the database. I found two solutions for this on the net, the first is to redirect the user after the submit ( via $q->redirect($q->url()) ), the second is to check if a reload was done, this is what im trying to do.

      Don't try to detect a reload. Read what mzedeler wrote: Implement transactions. Include a unique identifier in the submitted form and refuse to process the submitted form again if you see that identifier more than once.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Maybe i dont get the point, but i thought this was what i tried to do with this script: Passing an unique number to the form, check if it was send bevor, if it was do not write into the db again.
        Or do i understand something wrong?
        Sorry, my english is not that good.