• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Avoid submission of form multiple times

 
Sid Scud
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the user clicks the Submit button multiple times in rapid succession, multiple (duplicate)entries are inserted in the DB.
How to avoid this?
 
Les Dsouza
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I guess you could use javascript on the client side for this.
regards.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les, do you have any particular example or documentation that explains how to use javascript in this kind of problem??
cheers
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
To prevent website visitors resubmitting the same form data multiple times (by clicking the submit button on a web form, then the back button in the web browser), one can use a no-cache meta tag.
Insert the following HTML tag into the header part of the form template file:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
Hope this is useful stuff for u

Mahesh
 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out hte sychronizer token pattern published in "core j2ee patterns"
Basically what you do is, you give every form a unique ID, and a form can be submitted only once with the same ID. so teh subsequent submitions fail.
The mechnics is:
generate the ID, put it in the form as a hidden field, store the ID in session.
When the form is submitted check if the ID in request matches with the ID in session.
If they match, its a valid (first time) submition, remove the id from session and process the request
If they do not match, the submition is invalid.
If it is not clear and you don't have access to the book, feel free to ask questions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic