www.webdeveloper.com
Results 1 to 9 of 9

Thread: Concerning the use of hidden in <input>

  1. #1
    Join Date
    Jan 2006
    Posts
    18

    Concerning the use of hidden in <input>

    As I continue to learn HTML and PHP there is one thing I'd just do not understand. You create a <form>, build the various input types, 'text', 'password', etc and usually a 'submit' type. Then you build another input type of 'hidden', with accompanying name and value attributes.

    In the PHP code you then issue an if (isset($_POST['name attribute'])), which checks the name attribute of the hidden type.

    Why use the hidden attribute? You can just as easily use the name attribute of the submit type?

    I'm I missing something here?

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    Quote Originally Posted by CanMike
    Why use the hidden attribute?
    A hidden form control also has a value. You can use it to "save state" with a multi-page form. I use it to indicate that the form has been validated by JavaScript.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Jan 2006
    Posts
    18
    Thanks for taking the time to answer.

    I kind of understand the concept of 'save state', but given two input statements:

    <input type='submit' name='submit' value='Login' />
    <input type='hidden' name='submitted' value='TRUE' />

    my PHP code checks

    if (isset($_POST['submitted'])){

    $name1 = $_POST['submitted'];
    $name2 = $_POST['submit'];

    echo $name1; --> displays 'TRUE'
    echo $name2; --> displays 'Login'

    require_once('./includes/mysql_connect.php'); // Connect to db.
    code continutes....


    Isn't the 'save state' simply the value of $_POST variable?

  4. #4
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Normally hidden fields are used to contain values that are either created/changed by Javascript OR you have multiple instances of the form each of which has a different value for the hidden field so that you can tell which of the forms it was did the submission.

    Also the submit button may not be passed with the form if the form is submitted without actually clicking on the button but by some other means. Only currently selected buttons are passed with the form.
    Stephen

  5. #5
    Join Date
    Jan 2006
    Posts
    18
    OK, now I starting to get it. You can hold a value to be used, even if the button is not used.

  6. #6
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043
    I use it for a value brought forward from a previous page, and being carried on to the next, along with a value input from the present page, in php.
    Last edited by kiwibrit; 06-14-2006 at 07:07 PM. Reason: clarification (I hope)

  7. #7
    Join Date
    Jan 2006
    Posts
    18
    Now it all make sense.

    See, us old Oracle DBA's, COBOL/Java/ & PL/SQL developers can learn new trick if you hit us over the head hard enough.

    Thanks all

    I say, bring back green screens!

  8. #8
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    A web browser is just a 3270 with lipstick. Check out this form handler for a very common use of hidden fields.

    http://www.bignosebird.com/carchive/bnbform.shtml
    "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." Brian W. Kernighan

  9. #9
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Quote Originally Posted by ray326
    A web browser is just a 3270 with lipstick.
    Never thought about it quite that way before but I think that description is very accurate.
    Stephen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles