Multiple Form Post Using Javascript - Empty Post from FF

A

Adam

Hey,

I'm using JS to submit a form with image submit buttons, using the
following code...

(Page is here... http://www.cards2do.co.uk/addcard.php?card_id=292 )

**************************************************************************************

<form action="https://www.cards2do.co.uk/addcard.php" method="post"
id="loginform">
Username:

..................... Rest of Form.....................

<input type="hidden" name="submit" value="true"/>
<input type="image" src="images/buttons/login.gif" alt="Click To Login"
onclick="javascript:document.loginform.submit();"/>
</form>

**************************************************************************************

There are two forms on this particular page... They use identical code
except that the second form has a different name (also updated in the
onclick event), and the dummy submit variable has a different name to
help the PHP.

The problem...
Everything works perfectly in IE... both the user login and the "adding
card" form work great.
However in Firefox... the login works perfectly but the "adding card"
form does not. Using the PHP function "var_dump($_POST)" hsa shown me
that the post from firefox is a totally null array. No keys or values
are present at all. Firefox reported no Javascript errors in the
console when I ran it.

I would be extremely grateful if anyone knows the cause of the problem.
I would assume it's my Javascript rather than Firefox! : )

Many Thanks,

Adam King
Cards2do.co.uk
 
V

vdP

Adam said:
Hey,

I'm using JS to submit a form with image submit buttons, using the
following code...

(Page is here... http://www.cards2do.co.uk/addcard.php?card_id=292 )

**************************************************************************************

<form action="https://www.cards2do.co.uk/addcard.php" method="post"
id="loginform">
Username:

.................... Rest of Form.....................

<input type="hidden" name="submit" value="true"/>
<input type="image" src="images/buttons/login.gif" alt="Click To Login"
onclick="javascript:document.loginform.submit();"/>
</form>

**************************************************************************************
The problem...
Everything works perfectly in IE... both the user login and the "adding
card" form work great.
However in Firefox... the login works perfectly but the "adding card"
form does not. Using the PHP function "var_dump($_POST)" hsa shown me
that the post from firefox is a totally null array. No keys or values
are present at all. Firefox reported no Javascript errors in the
console when I ran it.

Surprisingly, my Firefox showed the following error after submitting the
form.

Error: document.loginform has no properties
Source File: https://www.cards2do.co.uk/addcard.php
Line: 1

To solve the problem replace the onclick attribute in the submit image
to onclick="javascript:document.getElementByID('loginform').submit();" .
That should work in Firefox and IE.

vdP
 
L

Lee

Adam said:
<input type="hidden" name="submit" value="true"/>
<input type="image" src="images/buttons/login.gif" alt="Click To Login"
onclick="javascript:document.loginform.submit();"/>

When you name a form field "submit", you destroy the built-in form attribute
"submit", which is the method you're trying to call in your onclick event
handler.
Rename the hidden form field.
 
A

Adam

Brilliant... Thanks for your help guys, I will try out your suggestions
tomorrow and let you know!

Cheers,
Adam
 
A

Adam

Hey,

I tried out both your suggestions but still no luck! Firefox still
sends empty posts for only the "add card" form on the page. It says
that document.getElementByID is not a function.. (I tried different
capitalisations of the function name just in case)

Do you guys have any other thoughts?



Cheers for your help so far!
Adam
 
T

Thomas 'PointedEars' Lahn

Adam said:
I tried out both your suggestions but still no luck! Firefox still
sends empty posts for only the "add card" form on the page. It says
that document.getElementByID is not a function.. (I tried different
capitalisations of the function name just in case)

You did not try `document.getElementById'. And

<input type="image" ...
onclick="javascript:document.getElementbyId('infoform').submit();"/>

is nonsense.

1. `javascript:' is nonsensical where supported as designed
(to generate an HTML document from script code; the submit()
method returns `undefined') and error-prone when not supported.
Omit that and add

<meta http-equiv="Content-Script-Type" content="text/javascript" />

to the `head' element.

2. The `input' element is descendant of the `form' element referred to.
If it were not already a submit control, that form element could be
easily referred to by `this.form'. No need for getElementById()
and the like.

3. input[type="image"] are submit controls, there is no need for scripting.

4. <http://hixie.ch/advocacy/xhtml>


HTH

PointedEars
 
A

Adam

Thanks Thomas...

I implemented the code vdP recommended to the letter. That was the
output Firefox gave in the console.

I tried removing the "onclick" attribute all together...
Unfortunately... still the same problem! IE is happy with the login and
the "addcard" form, but Firefox only posts the login form.

Your point number 4... I had a browse through that page, are you saying
you think the problem was due to the pages being served as text/html
MIME type? (or something along those lines?)

So with the page now using no JS to submit the forms, the problems
remain! : (

I'm still totally clueless about this one... any more ideas? : )

Thanks,
Adam
 
T

Thomas 'PointedEars' Lahn

Adam said:
I implemented the code vdP recommended to the letter. That was the
output Firefox gave in the console.

That"? said:
I tried removing the "onclick" attribute all together...
Unfortunately... still the same problem! IE is happy with the login and
the "addcard" form, but Firefox only posts the login form.

Clear your cache, then try again. If it still does not work, and there is
no JS code whatsoever left, most certainly you do not have a JS problem.
Your point number 4... I had a browse through that page, are you saying
you think the problem was due to the pages being served as text/html
MIME type? (or something along those lines?)
Possibly.

So with the page now using no JS to submit the forms, the problems
remain! : (

Maybe you are assigning an event listener somewhere else or a buggy
extension interferes.
I'm still totally clueless about this one... any more ideas? : )

Not without more/the entire source code, preferably provided through a URL.


PointedEars
 
A

Adam

Thank you Jasen!

It was an xhtml error... (missed a closing tag). Guess IE blindly
ignored it, while Firefox was (rightly) getting confused. So it's all
working now. I'll use the validator more in future!


Thanks for your help...
Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top