Form submits twice

3.3k Views Asked by At

I have a form that processes a payment, but approximately one in every 300 payments comes though twice, my logs show that there were two requests for all these occurrences.

I implemented some JavaScript that disables the submit button after it's clicked, and it seems to work fine for me, but I'm still getting double submissions every now and then.

Does anyone know anything else that could be causing the form to be submitted twice?

2

There are 2 best solutions below

5
On BEST ANSWER

As Dagon says, server-side checks are your friend here. Give each instance of the form a randomly generated key (guid would be nice), and store that in the database. Don't accept forms that contain a key that already exists in the db.

Also, are you simply displaying HTML after your form processing logic executes? If so, try redirecting after you process the form.

0
On

It is a way: after user presses form submit button, disable it with javascript. That should prevent user from double submitting the form accidently. It works for all sites we implement it like because. Because sometimes user gets impatient and clicks form submit button several times, thats why you get double requests. What you need to make sure it works for all the browsers (disabling the button I mean).

Also you could do it on server side, it just is harder.

We use similar to the upvoted answer in Enable/disable submit button with jQuery and Coldfusion server code