How to test if a form has been submitted?

Discussion in 'HTML' started by Ken Adams, Mar 15, 2005.

  1. Ken Adams

    Ken Adams Guest

    Basically I have a form submit to the same page and have it output the
    results of the submit to the same page. How can I test to see if something
    was submitted inorder to get to this page or if this is the first time to
    the page. Possible a javascript or JSP method would be fine maybe even the
    right way to go.

    Thanks a bunch
    Ken
     
    Ken Adams, Mar 15, 2005
    #1
    1. Advertising

  2. Ken Adams wrote:
    > Basically I have a form submit to the same page and have it output
    > the results of the submit to the same page. How can I test to see
    > if something was submitted inorder to get to this page or if this
    > is the first time to the page. Possible a javascript or JSP method
    > would be fine maybe even the right way to go.


    You don't say what language you're using, but check the POST variables
    at the start of the code.

    $bar = $_POST['foo'];
    if ($bar) {
    // do stuff here
    }

    --
    -bts
    -This space intentionally left blank.
     
    Beauregard T. Shagnasty, Mar 15, 2005
    #2
    1. Advertising

  3. Ken Adams

    Toby Inkster Guest

    Ken Adams wrote:

    > Basically I have a form submit to the same page and have it output the
    > results of the submit to the same page. How can I test to see if something
    > was submitted


    I tend to include this in the form:

    <input type="hidden" name="submitted" value="1">

    And then test:

    <?php
    if ($_REQUEST['submitted']==1) {
    // form was submitted
    } else {
    // form not submitted
    }
    ?>

    BTS's solution will sometimes break -- for example, if $_POST['foo'] is
    the number '0' or the string 'False'. (Though it could be made to work
    using the isset() function.)

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Mar 15, 2005
    #3
  4. Toby Inkster wrote:

    > BTS's solution will sometimes break --


    True enough. I should have gone into more details, but since we don't
    yet know the language, I was being sparse. <g>

    My php forms do much as you describe, though I don't use hidden values.

    --
    -bts
    -This space intentionally left blank.
     
    Beauregard T. Shagnasty, Mar 15, 2005
    #4
    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. Anon
    Replies:
    39
    Views:
    2,120
    Joona I Palaste
    May 2, 2004
  2. subbu
    Replies:
    1
    Views:
    1,385
    Andrew Thompson
    Jul 27, 2006
  3. bill.wu
    Replies:
    0
    Views:
    295
    bill.wu
    Jan 17, 2008
  4. Craig Buchanan

    Test if GridView has been databound

    Craig Buchanan, Sep 29, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    476
    Craig Buchanan
    Sep 29, 2008
  5. clarket

    Checking if a form has been submitted.

    clarket, Aug 24, 2005, in forum: Javascript
    Replies:
    2
    Views:
    97
    Darkstar 3D
    Aug 24, 2005
Loading...

Share This Page