Multiple Form Post Using Javascript - Empty Post from FF

Discussion in 'Javascript' started by Adam, Nov 21, 2005.

  1. Adam

    Adam Guest

    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
     
    Adam, Nov 21, 2005
    #1
    1. Advertising

  2. Adam

    vdP Guest

    Adam wrote:
    > 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
     
    vdP, Nov 21, 2005
    #2
    1. Advertising

  3. Adam

    Lee Guest

    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.
     
    Lee, Nov 21, 2005
    #3
  4. Adam

    Adam Guest

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

    Cheers,
    Adam
     
    Adam, Nov 22, 2005
    #4
  5. Adam

    Adam Guest

    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
     
    Adam, Nov 22, 2005
    #5
  6. Adam wrote:

    > 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
     
    Thomas 'PointedEars' Lahn, Nov 22, 2005
    #6
  7. Adam

    Adam Guest

    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
     
    Adam, Nov 23, 2005
    #7
  8. Adam wrote:

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


    "That"? <URL:http://www.jibbering.com/faq/faq_notes/pots1.html>

    > 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
     
    Thomas 'PointedEars' Lahn, Nov 23, 2005
    #8
  9. Adam

    Adam Guest

    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
     
    Adam, Nov 24, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,045
    Klaus Johannes Rusch
    Jul 16, 2003
  2. Lukas
    Replies:
    3
    Views:
    834
    spiff
    Nov 10, 2005
  3. Lew
    Replies:
    0
    Views:
    1,405
  4. ERobishaw
    Replies:
    1
    Views:
    842
    Anthony Jones
    Mar 22, 2008
  5. Replies:
    7
    Views:
    171
    Michael Granger
    Feb 15, 2008
Loading...

Share This Page