|
| Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more. |
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 | |
|
Join Date: May 2002
Location: Idaho
Posts: 261
Reputation: 32
|
FireFox submits form twice?
I have a couple of forms that are misbehaving in FireFox, but work fine in IE.
In all the affected forms: * The person enters data into forms, using any combination of text fields, textareas, radio buttons, and SELECT fields. * The person clicks a button that says "submit" (which is really just a button, not a submit button). * A javascript function validates all of the fields entered, and stops the submission if there is an error. * Once the validation is complete, and the form is ready for submission, the script calls " document.myForm.submit()" to submit the form. Sample (obviously not working code): Quote:
(notice the form doesn't really have a "submit"-type button) THE PROBLEM: In IE, the script performs as expected. In FireFox (tested in v2.0.0.3): * if the form validates correctly (tested by the " if (ready to submit) " above), it gets submitted twice: once with all of the data, and once with all fields blank (or default). * if the form fails validatation, it gets submitted once with all fields blank (or default). Am I coding something wrong here? Why is FireFox submitting the form when I don't specifically call the "document.myForm.submit()" function? Last edited by Sparhawk : 4-15-07 at 11:02 PM. Reason: clarifying the problem & symptoms |
|
|
|
|
|
#2 |
|
Custom User Title
Join Date: Sep 2004
Location: Mass
Posts: 1,765
Reputation: 208
|
I'm a total hack at this kind of thing...but when I use javascript validation for a form, I set the onsubmit property of the opening form tag to run the validation routine, then use the action property to call the form processing script. it appears as though the data are submitted twice (or at least in FF) - once through the action, and once through the myform.submit?
again, total hack, could be way off... |
|
|
|
|
#3 | ||
|
Join Date: May 2002
Location: Idaho
Posts: 261
Reputation: 32
|
Thanks for the suggestion, but I tried that. Even changing my form tag to:
Quote:
... and changing my submit button to: Quote:
The form still gets submitted twice. Same situation: one with the correct data, and one with blank or default data. |
||
|
|
|
|
#4 |
|
Rick
Join Date: May 2002
Location: Minneapolis, MN
Posts: 1,515
Reputation: 174
|
Insert 'return true;' on a new line after the document.form.submit(); I suspect that the function is apparently always returning a result of 'false' which is why Firefox assumes that it has to allow the HTML 'submit' button's submit function to be executed.
__________________
Richard L. Trethewey Search Engine Optimization Tips Disney Art and Collectibles Book Reviews Management Consultant Minneapolis |
|
|
|
|
#6 |
|
Registered
Join Date: Apr 2007
Location: UK
Posts: 1
Reputation: 0
|
any solutions..
Hey guys,
I faced a similar probelm while developing a massive network fault diagnosis application where in i run some masive tests which may take around 2-3 minutes to complete. And some users of this applications with firefrox browser complained that the tests are run twice when they submit the form. In the action of the form i am actually calling another perl file which initiates the tests by calling binary on AIX platform. I was clueless about this problem and dont know whats happenning here. After some debugging i found that the action is verifies in firefrox and thats the place the action is getting called up twice. Any pointers in this regard would be really helpful. |
|
|
|
|
#7 |
|
Join Date: Oct 2002
Location: Dallas
Posts: 2,699
Reputation: 213
|
what happens if you use this?
<input type="button" value="Check First" onclick="submitMe(); return;"> |
|
|
|
|
#8 | |
|
Join Date: May 2002
Location: Idaho
Posts: 261
Reputation: 32
|
I figured it out (with the help of W3Schools.com)!
For others dealing with the same problem, here is the adjusted pseudo-code: Quote:
Doing it this way works with both IE and FireFox. Here's how things work: * The person clicks the "Check First" button. * The "checkAndSubmitMe()" function is run, returning 'false' if the form should not be submitted, or 'true' if the form should be submitted. * If 'true' is returned, then the "action" of the form is submited. Last edited by Sparhawk : 5-27-07 at 04:10 AM. |
|
|
|
|
|
#9 |
|
Join Date: May 2002
Location: Idaho
Posts: 261
Reputation: 32
|
False alarm.
It seemed to work for a while, but now it is back to doing the same thing again. |
|
|
|
|
#10 | |||
|
Join Date: May 2002
Location: Idaho
Posts: 261
Reputation: 32
|
My adjusted code above still exhibits this problem:
Quote:
But it does resolve this problem: Quote:
And, some more information: My CGI "action" script sends an e-mail to me with the contents of the form. When the person uses IE, I get the one correct e-mail submission. When the user browses with FireFox, I get one correct submission and one blank submission. Using the Perl variable $ENV{'REQUEST_METHOD'}, I checked to see how the form was getting submitted. To do this, I simply included the value of $ENV{'REQUEST_METHOD'} in the text of the e-mail submission. On the first (correct) submission, the request method is POST, as I wrote in the form: Quote:
|
|||
|
|
|
|
#11 | ||||
|
Join Date: May 2002
Location: Idaho
Posts: 261
Reputation: 32
|
Oh good God, that was stupid. I figured out the problem. Although I don't konw why IE & FireFox behave differently, this is what the situation was:
Every page on my site has a left border menu written in JavaScript. Included in that menu is a randomly-selected image. Once the person clicks the submit button and goes to the confirmation screen (the same page that sends the e-mails), the randomly-selected image is displayed again on the left menu. The JavaScript code for that image tag was: Quote:
The picture filename and the link (to the full-size picture) were intentionally left blank, because further down the page there is code that fills it in. It appears that when given an IMG tag with no associated file, the browsers treat the "image" differently: In Internet Explorer: The right-click "Properties" of the missing image in IE is attached as "ie_missingimageproperties2.JPG". If the SRC of the IMG tag is "", IE substitutes the current folder URL, and shows a "broken" image: In effect, IE treats the IMG tag like (italics is an example): Quote:
In FireFox: The right-click "Properties" of the missing image in FireFox is attached as "ff_missingimageproperties2.JPG". If the SRC of the IMG tag is "", FireFox substitutes the current filename URL, and shows a broken image: In effect, FireFox treats the IMG tag like (italics is an example): Quote:
Because FireFox replaces a missing IMG SRC with the URL of the current page, and the current page is the "form.cgi" file that grabs the form data, sends the e-mails and displays the confirmation screen, the CGI script gets run twice: the first one as expected, the 2nd one in the blank image spot with no POST data, and shows as a GET instead. So, to resolve the problem, I substituted the code with: Quote:
This way, FireFox doesn't run the script a 2nd time from the IMG tag. The most annoying thing about this problem is that I didn't think the IMG tag would have anything to do with how the form got submitted. |
||||
|
|
|
|
#12 |
|
Join Date: Apr 2007
Location: USA
Posts: 402
Reputation: 26
|
Transparent would be a better choice in case the background color changes. I've seen that used a lot.
__________________
-- Vinyl records for your collection at Noble-Efforts.com ---- Find a record turntable at BuyRecordPlayers.com -- -- Set your sweet tooth on fire at FlamingHotCandy.com ---- Looking for a GPS device? Check buyGPSdevice.com -- -- Check out my WordPress experiment: Defend Your Right To Offend at phreedom.us -- |
|
|
|
|
#13 | |
|
Join Date: May 2002
Location: Idaho
Posts: 261
Reputation: 32
|
Quote:
True, but the script loads fast enough that the graphic isn't even seen. And since the only image editor I have is MS Paint, it doesn't do transparent GIFs, does it? Or do you have a 1x1 transparent GIF you could attach in this thread for me to use? |
|
|
|
|
|
#14 |
|
Join Date: Apr 2007
Location: USA
Posts: 402
Reputation: 26
|
Sure. Haven't used Paint since Win3.1, couldn't tell you its current limitations.
Can you find it? Try this: <<URL removed at request of poster>>
__________________
-- Vinyl records for your collection at Noble-Efforts.com ---- Find a record turntable at BuyRecordPlayers.com -- -- Set your sweet tooth on fire at FlamingHotCandy.com ---- Looking for a GPS device? Check buyGPSdevice.com -- -- Check out my WordPress experiment: Defend Your Right To Offend at phreedom.us -- Last edited by Doc C : 5-29-07 at 03:51 PM. Reason: URL removed at request of poster. |
|
|
|
|
#15 |
|
Join Date: Apr 2007
Location: USA
Posts: 402
Reputation: 26
|
I really did attach a 1x1 transparent gif file, but how do you right-click on a 1x1 invisible picture? I see it has been downloaded 14 times, must be a way. Anyone?
Never mind, I'm a little slow, but I found it.
__________________
-- Vinyl records for your collection at Noble-Efforts.com ---- Find a record turntable at BuyRecordPlayers.com -- -- Set your sweet tooth on fire at FlamingHotCandy.com ---- Looking for a GPS device? Check buyGPSdevice.com -- -- Check out my WordPress experiment: Defend Your Right To Offend at phreedom.us -- |
|
|
|
|
#16 |
|
Moderator
Join Date: Mar 2006
Location: Southern CA
Posts: 5,044
Reputation: 286
|
Hold down your left mouse button and move the cursor from left to right starting on the left side of the Attached Images box. You should get a highlighted area. That is the gif file.
Right click to Copy and then paste it somewhere on your hard drive.
__________________
"You don't really understand human nature
unless you know why a child on a merry-go-round will wave at his parents every time around -- and why his parents will always wave back." -William D. Tammeus Last edited by Doc C : 5-29-07 at 07:59 PM. Reason: somewhere not someone. |
|
|
|
|
#17 |
|
Join Date: Apr 2007
Location: USA
Posts: 402
Reputation: 26
|
Or, from the "Threads in Forum" view, click on the paperclip icon for the thread to download any of the attachments in that thread.
__________________
-- Vinyl records for your collection at Noble-Efforts.com ---- Find a record turntable at BuyRecordPlayers.com -- -- Set your sweet tooth on fire at FlamingHotCandy.com ---- Looking for a GPS device? Check buyGPSdevice.com -- -- Check out my WordPress experiment: Defend Your Right To Offend at phreedom.us -- |
|
|
|
|
#18 |
|
Moderator
Join Date: Mar 2006
Location: Southern CA
Posts: 5,044
Reputation: 286
|
Or click your heels three times and say "there's no place like home". Whooops. That's not right.
![]()
__________________
"You don't really understand human nature
unless you know why a child on a merry-go-round will wave at his parents every time around -- and why his parents will always wave back." -William D. Tammeus |
|
|
![]() |
| Thread Tools | Search this Thread |
|
|