Duplicate Form Submissions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SeanF
Forum Newbie
Posts: 2
Joined: Mon Mar 07, 2011 9:56 am

Duplicate Form Submissions

Post by SeanF »

I have a name entry form where people enter names for name badges that get written to a MySQL database.

The problem is, if there is a short lag after hitting the "submit" button, it will duplicate the entries. ore even worse, if the user double clicks or triple clicks "submit" (even when the response time is "normal"), there will be double or triple the entries.

How can I avoid duplicate entries?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Duplicate Form Submissions

Post by Benjamin »

Add this code to your submit button, it will disable it when it is clicked the first time.

onClick="this.form.submit(); this.disabled=true; this.value='Sending…'"
SeanF
Forum Newbie
Posts: 2
Joined: Mon Mar 07, 2011 9:56 am

Re: Duplicate Form Submissions

Post by SeanF »

Great, Thanks! I added the code you suggested and when I click "Submit Names" I see the "Sending..." message but the contents of the form don't get submitted to the database. What should I be looking for as an error?

My code looks like the attached image. (because I am new, some characters in my code are not allowed??)
Attachments
Code snippet
Code snippet
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Duplicate Form Submissions

Post by Benjamin »

Hmm, perhaps remove the this.form.submit(); portion. In your browser console you should be able to check for any errors, and also check to see what was posted.
Post Reply