Re: Preventing multiple submits
[email protected] Thu, 17 Feb 2005 13:11:50 -0600
| Newsgroups | gmane.comp.apache.mod-ruby |
|---|---|
| Message-ID | <[email protected]> |
Correct me if I'm wrong on this, but I think a cookie has to make a round trip back to the client to be set, so that would not prevent resubmits if the user clicks again while the original request is still processing. Another low-tech-ish way to deal with this would be to have your app code check the database before inserting a new record for entries from the same user along with some distinguishing feature of the item -- for example, if it were a BBS post, you could check the Subject line; for a user account entry, you could concatenate FirstName + LastName -- and set a time window, say two minutes. So, in short -- if: Same user creating the entry Same FirstName + LastName In the last two minutes You could safely assume that it's a re-post , and you could return an error to users notifiying them that they are attempting a duplicate post. This might be a nice fallback is the user has JavaScript turned off, and you can't just disable the Submit link after a post. Matthew On Thu, Feb 17, 2005 at 10:40:24AM -0800, the entity known as [email protected] wrote: > Andi Scharfstein, > > On Thu, Feb 17, 2005 at 12:39:22PM +0100, Andi Scharfstein <[email protected]> wrote: > > Hi, > > on my website, there is a form where users can submit data to the > > site. I was just wondering if there was a simple (server-side) way to > > check if the user has already submitted something and preventing him > > from submitting the same thing twice (because he clicked on 'Submit' > > multiple times because the site took a little longer to load, or > > something along those lines). Can you achieve this in mod_ruby without > > resorting to more than moderately complex measures? > > You could use a cookie. > > When form is submitted, check for cookie. If set, assume it is a > resubmit. If no cookie is present, assume it is a new submit and > then set a cookie to prevent another submit. >