Forms submitting twice in Firefox

Recently I uncovered an extremely annoying and difficult to find bug in a website I’ve been modifying a client. There are two things I dislike, the first being debugging code where there exists some obscure error, the second and the one I dislike the most is debugging someone else’s code where there exists some obscure error.

Poorly written, poorly commented (something I also do but should improve), poorly formatted, and all round poorly done, is is the state of the code I was faced with. The predicament you might ask or yell! I was adding an item to a shopping cart, but in FireFox it was being added twice, where as in IE 7 only once, so begins the bane of my existance (for the day).

Now first things first, check the SQL… “nup that’s perfect”, ok send me an email every time something gets added to the database. Received 2 emails. ….*Pulls some hair out*. Digging into my repertoire, I began utilising all my knowledge of debugging, in between extracting more chunks of hair from any place I could find, (at this stage there isn’t much left but on the bright side I have a nice Brazilian, and I could be in the Olympics in swimming.)

Then comes Google, the saviour of many, the enemy of few (except yahoo, ninemsn, hotbot, altavista, etc). Enter Search Terms : Form Submitting Twice in FireFox. Results – a Plethora of semi useful information.

From the rubble a solution was found – from Sparhawk – to sum up his post, any element in your html that contains an empty src attribute will, in FireFox, invoke a call to the same page. In IE it invokes a call to the current working directory.

Elements that generally have a src attribute are external cs, javascript scripts, and by far the most common, images. I’m yet to find the empty src attribute (as I didn’t write the code, the main file of the website is >250kb, about 8 pages are included every page load, and I found a better solution – keep reading) but sometimes the removal of it is not needed, simply this, if you are getting duplicate entries into the database, change the form type to a POST instead of a GET. Simply the image loads the same page but with no variables, most form submit page checks that the submit button variable exists, if not it won’t continue to run. If you are getting duplicate entries and are still unsure about whether the entry is being added by your sql command, append the date (something that shows what second it is) to a title, many of my duplicate entries were at elast 2 – 4 seconds apart.

For optimal performance it would be better to remove the empty src if it can be found. I hope this helps someone as i spent easily 3 – 5 hours trying to get it to work, when all I needed to do was replace the POS in POST with GE. The slowest typist could achieve this in far less time then I took to debug. :(

Nuff Said. Comment if it helped you.

Responses are currently closed, but you can trackback from your own site.

Comments are closed.