When does the html input type submit get set?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Taras_96

    When does the html input type submit get set?

    Hi everyone,

    I've got a rather unconventional architecture that I'm having problems
    with...

    I have a form called "searchForm ", that has an input of type "submit"
    (with name = "submitButt on for argument sake). What happens when the
    form is submitted (when the submit button is clicked...) depends on
    some previous user input. In one case, the onsubmit handler calls a
    function that does basic input checking, and returns true if all the
    inputs are correct, and thus submits the form:

    onsubmit = "return submitSearchFor m"

    In the other case, the onsubmit handler calls some java functions that
    accomplish some other functionality, and the java functions themselves
    call submit on the form:

    onsubmit = "doStuff(); return false;"

    function doStuff()
    {
    //..do some other complicate stuff
    document.getEle mentById('searc hForm').submit( )
    }

    In the latter case, the form seems to get submitted, because the page
    reloads. Also, the $_POST variables that the form submits are set.
    However, in the latter case, the $_POST['submitButton'] variable is not
    set, even though the form was submitted by clicking on the submit
    button! In the prior case, the $_POST['submitButton'] is set.Why is
    this the case? Does it have something to do with the fact that the form
    was submitted by a function, rather than the onsubmit handler?

    Are there any elegant workarounds to this problem (I use the
    $_POST['submitButton'] value to check if the form has been submitted -
    if it has, I do some processing on the form's inputs)?. One way I can
    think of is having a hidden input called 'formSubmitted' which is
    initially set to false, and prior to calling submit() on the form, you
    set this input to true, and you can test to see if this value is true
    in addition to testing if $_POST['submitButton'] is set:

    if ( isset($_POST['submitButton']) || formSubmitted == 'true')
    {
    //.. do some form processing
    }

    Any help would be appreciated!

    Cheers

    Taras

  • John Dunlop

    #2
    Re: When does the html input type submit get set?

    Taras_96:
    [color=blue]
    > document.getEle mentById('searc hForm').submit( )[/color]

    [...]
    [color=blue]
    > However, in the latter case, the $_POST['submitButton'] variable is not
    > set, even though the form was submitted by clicking on the submit
    > button![/color]

    Your inkling was right. The form wasn't submitted using the submit
    button but by the javascript function submit(), because onsubmit
    returned false, and so the name-value pair of the submit button was not
    sent as part of the form data, the submit button not being a
    'successful control'.
    [color=blue]
    > One [workaround] I can think of is having a hidden input called 'formSubmitted'
    > which is initially set to false, and prior to calling submit() on the form, you
    > set this input to true, and you can test to see if this value is true in addition to
    > testing if $_POST['submitButton'] is set:[/color]

    Only concern is that it relies on javascript to toggle the hidden
    value, but then maybe that's neither here nor there since you appear
    to be relying heavily on javascript already. I would think a hidden
    input of some sort is the way to go.

    --
    Seoc

    Comment

    • Taras_96

      #3
      Re: When does the html input type submit get set?

      Thanks, its good to get guesses confirmed by someone that knows what
      they're talking about :)

      Yeah, the site heavily relies on javascript, and I don't see why this
      would be a problem with today's modern browsers (I imagine most of the
      population would use either FF, IE, NN, or Safari). The only exception
      I can think of is browsing via WAP.

      Cheers

      Taras

      Comment

      • Jerry Stuckle

        #4
        Re: When does the html input type submit get set?

        Taras_96 wrote:[color=blue]
        > Thanks, its good to get guesses confirmed by someone that knows what
        > they're talking about :)
        >
        > Yeah, the site heavily relies on javascript, and I don't see why this
        > would be a problem with today's modern browsers (I imagine most of the
        > population would use either FF, IE, NN, or Safari). The only exception
        > I can think of is browsing via WAP.
        >
        > Cheers
        >
        > Taras
        >[/color]

        It's a problem because more and more people turn off javascript, largely
        because of all the holes in browsers (not to mention any names).

        IMHO, javascript is great for improving the functionality of a site -
        but no site should rely on javascript for it's basic functionality.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        Working...