SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why put input hidden field in display:none style?

    Hello,
    In Django framework, I find the hidden forms fields in a div style="display:none"

    For example for the security token

    <div style="display:none">
    <input type="hidden" name="csrfmiddlewaretoken" value="894yb3poe6de233c6b3742685a98472f">
    </div>

    I want to know the reason, because in any case, all fields of type hidden are not visible.

    Thank you.

  2. #2
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    There is no reason.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member apxred's Avatar
    Join Date
    Jul 2012
    Location
    India
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The basic reason behind using hidden fields is to pass some value in PHP, which you do not want to be shown in your webpage directly. And the person used style to hide the Div box, to hide it too.. There is no big deal with it.

    Many people use Hidden input types to pass a large number of variables according to needs

  4. #4
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, so put the hidden DIV box is useless since the field is already hidden type.

  5. #5
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    correct, hidden inputs are ... hidden from the page

  6. #6
    SitePoint Member apxred's Avatar
    Join Date
    Jul 2012
    Location
    India
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by laresistance2 View Post
    Okay, so put the hidden DIV box is useless since the field is already hidden type.
    yes, that's useless.. unless you have some css styles applying at default Div tag.. if that is the case, you will need this div with style... again, only if you feel the need to have a DIV there
    that's pretty funny, am i stressing too much ?

  7. #7
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,729
    Mentioned
    31 Post(s)
    Tagged
    0 Thread(s)
    That does seem rather redundant. It is possible, however that i was done so as to be able to put the input there (for some on known reason) while not disturbing the flow of other elements. Still.. odd

  8. #8
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,892
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    As discussed here (among others) in older browsers (i.e., legacy IE) hidden input fields took up some space. Wrapping them in a display: none div makes sure they're completely invisible and don't take up any space.
    Indeed I'd say that nowadays this is no longer needed as all browsers render hidden inputs correctly now.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  9. #9
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your answers.
    PS: I just noticed that Django is also the same for its security token, it's weird that they add a box hidden div to keep compatibility with older browsers and it support the HTML5 which is not compatible with the older web browsers.


Tags for this Thread

Bookmarks

Posting Permissions

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