Form Require Hidden Input Not Working

Discussion in 'HTML' started by tea-mad brit, Jan 17, 2006.

  1. tea-mad brit

    tea-mad brit Guest

    The last input in my form is hidden.
    <input type="hidden" name="required" value="name,email,phone,organization"/>
    I have been out of the loop with writing code for a while. This validates,
    but does not work. I am trying to avoid a user clicking on the send button
    and submitting a blank form. The form goes to a PHP handler and all that
    works fine.
    Any thoughts?
    Thanks

    --
    Christopher
    www.teamadness.com
    slightly true stories of tea drinking
     
    tea-mad brit, Jan 17, 2006
    #1
    1. Advertising

  2. tea-mad brit

    Ed Jay Guest

    "tea-mad brit" <> wrote:

    >The last input in my form is hidden.
    ><input type="hidden" name="required" value="name,email,phone,organization"/>
    >I have been out of the loop with writing code for a while. This validates,
    >but does not work. I am trying to avoid a user clicking on the send button
    >and submitting a blank form. The form goes to a PHP handler and all that
    >works fine.
    >Any thoughts?
    >Thanks


    You might try using onsubmit="return somefunction();" and having
    somefunction() check the form field(s) for empty. If the form is empty,
    return false. If the form isn't empty, return true.

    If you want, using innerHTML, you can have somefunction() print an error
    message to the screen before returning false..

    --
    Ed Jay (remove M to respond by email)
     
    Ed Jay, Jan 17, 2006
    #2
    1. Advertising

  3. tea-mad brit wrote:

    > The last input in my form is hidden.
    > <input type="hidden" name="required"
    > value="name,email,phone,organization"/>


    If you plan to serve your XHTML as text/html[1], then appendix C requires a
    space before that /.

    > I have been out of the loop with writing code for a while. This validates,
    > but does not work. I am trying to avoid a user clicking on the send button
    > and submitting a blank form. The form goes to a PHP handler and all that
    > works fine.


    What that code should do is submit to the server side script the data in the
    value attribute attached to the key that is the value of the name field.
    Nothing about it actually makes any fields required.

    The server side script can then check what values were submitted based on
    that field and complain to the user if they haven't entered the required
    values.

    You could also do something similar with client side JavaScript.

    Either way, user's can modify the required input if the want to, so its no
    good if you really want to prevent people not submitting those fields.
    (OTOH, it does make it rather difficult for the user to have a successfully
    processed form by accident).

    [1] If you don't then you are going to have a really limited audience, if
    you do then there isn't any point in using XHTML instead of the better
    supported HTML 4.01 in the first place.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jan 17, 2006
    #3
  4. tea-mad brit

    tea-mad brit Guest


    > Either way, user's can modify the required input if the want to, so its no
    > good if you really want to prevent people not submitting those fields.
    > (OTOH, it does make it rather difficult for the user to have a
    > successfully
    > processed form by accident).
    >
    > [1] If you don't then you are going to have a really limited audience, if
    > you do then there isn't any point in using XHTML instead of the better
    > supported HTML 4.01 in the first place.
    >
    > --
    > David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    > Home is where the ~/.bashrc is


    Yes, I just need to help the user avoid a mistake and get a false count on
    how many people fill out the form.

    I don't know anything about JS but a little PHP. If I understand correctly,
    I need to modify the server side script and that the required stuff in the
    input form isn't doing anything?
    Thanks.
     
    tea-mad brit, Jan 17, 2006
    #4
  5. tea-mad brit wrote:

    > I don't know anything about JS but a little PHP. If I understand
    > correctly, I need to modify the server side script and that the required
    > stuff in the input form isn't doing anything?


    The required stuff in the input form is providing data that gets sent to the
    server. The server side script could use this to decide what to test for in
    its sanity checking routines.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jan 17, 2006
    #5
  6. tea-mad brit

    gerg Guest

    David Dorward wrote:
    > tea-mad brit wrote:
    >
    >
    >>I don't know anything about JS but a little PHP. If I understand
    >>correctly, I need to modify the server side script and that the required
    >>stuff in the input form isn't doing anything?

    >
    >
    > The required stuff in the input form is providing data that gets sent to the
    > server. The server side script could use this to decide what to test for in
    > its sanity checking routines.
    >


    use something like this:

    processor.php

    <?

    session_start();

    // the $_POST variables should be the same as your form names.

    if( (empty($_POST['email'])) || (empty($_POST['name'])) ||
    (empty($_POST['phone'])) ){

    // return to the form and display an error message.

    $_SESSION['errormessage']="Please fill out all form fields.";
    header("Location:http://www.mysite.com/myform.php");
    exit();

    }
    else
    {
    // execute code that should happen if all fields are filled in.
    }

    ?>


    myform.php

    <?

    //this line makes available any session variables already set, like the
    error message above.

    session_start();

    //if there is an error message available, display it

    if($_SESSION['errormessage']){
    echo $_SESSION['errormessage'];
    }

    ?>

    Your form would then go here.

    Hope that helps.

    Greg
     
    gerg, Jan 17, 2006
    #6
    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. Brock Allen
    Replies:
    0
    Views:
    468
    Brock Allen
    Apr 12, 2005
  2. Quasimido CSS
    Replies:
    2
    Views:
    6,634
    Quasimido CSS
    Nov 7, 2005
  3. Walter
    Replies:
    6
    Views:
    246
    Bob Barrows [MVP]
    Sep 17, 2004
  4. chumley
    Replies:
    6
    Views:
    1,137
    Adrienne Boswell
    Mar 6, 2010
  5. Replies:
    2
    Views:
    122
    dmcreyno
    Jan 5, 2005
Loading...

Share This Page