PHP with Style="Display:None"?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chunk1978
    New Member
    • Jan 2007
    • 224

    PHP with Style="Display:None"?

    hi there...

    i'm about to embark on my very first PHP code journey (i've been saying that for a while... so sometime soon i hope... anyway)...

    before i begin my exciting new journey into PHP land, i would like to know if PHP will send hidden HTML form elements or not?...

    for example: if a user makes a selection in my HTML form that triggers my wonderfully dynamic HTML to set a DIV to STYLE="DISPLAY: NONE", is it possible to tell PHP not to send the DIV's data if it's hidden (even-though there will be a "<?PHP" tag on that line)? or is true that the only real way around this to use the DOM method with Remove Child and Append Child?

    for me, setting STYLE="DISPLAY: NONE" or STYLE="DISPLAY: BLOCK" is as easy as pie... but removing and appending children, well... that's a little confusing...

    so what are my options?
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by chunk1978
    hi there...

    i'm about to embark on my very first PHP code journey (i've been saying that for a while... so sometime soon i hope... anyway)...

    before i begin my exciting new journey into PHP land, i would like to know if PHP will send hidden HTML form elements or not?...

    for example: if a user makes a selection in my HTML form that triggers my wonderfully dynamic HTML to set a DIV to STYLE="DISPLAY: NONE", is it possible to tell PHP not to send the DIV's data if it's hidden (even-though there will be a "<?PHP" tag on that line)? or is true that the only real way around this to use the DOM method with Remove Child and Append Child?

    for me, setting STYLE="DISPLAY: NONE" or STYLE="DISPLAY: BLOCK" is as easy as pie... but removing and appending children, well... that's a little confusing...

    so what are my options?
    Display:none is effects the rendering of the page. PHP gets executed before the page ever existed. If you know that a section of the page will never be there, you can just not send it. But, after the page has been sent to the browser, you cannot modify it with php (at least not without the help of ajax). DOM would be your best bet here, as gruesome as that is.

    Comment

    • chunk1978
      New Member
      • Jan 2007
      • 224

      #3
      Originally posted by Motoma
      Display:none is effects the rendering of the page. PHP gets executed before the page ever existed. If you know that a section of the page will never be there, you can just not send it. But, after the page has been sent to the browser, you cannot modify it with php (at least not without the help of ajax). DOM would be your best bet here, as gruesome as that is.
      humm... ok... what about if the field/dropmenu contains no data (is blank) or value ("options[0].selected=true" )... will PHP still display these blank fields, regardless if they're hidden or not?

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by chunk1978
        humm... ok... what about if the field/dropmenu contains no data (is blank) or value ("options[0].selected=true" )... will PHP still display these blank fields, regardless if they're hidden or not?
        Those fields won't exist until PHP creates them.

        Comment

        • chunk1978
          New Member
          • Jan 2007
          • 224

          #5
          Originally posted by Motoma
          Those fields won't exist until PHP creates them.
          i'm clearly getting ahead of myself as i don't really understand... ok... so the code below is a perfect example of what i mean exactly...

          HTML form:
          Code:
          <html>
          <body>
          <form action="phpscript.php" method="post">
          Name: <input type="text" name="name" style="display:none"/>
          <input type="submit" />
          </form>
          </body>
          </html>
          PHP script:
          Code:
          <html>
          <body>
          Welcome <?php echo $_POST["name"]; ?>.<br />
          </body>
          </html>
          so even if the html isn't displaying the name field, will PHP still print/echo it with the PHP output... or is there a way to write the PHP tag a certain way to tell it that if the HTML field is hidden, don't echo... maybe something like this:

          Code:
          <if (form.name.value = "" || form.name.display.none=true) {<?php echo $_POST["name"]; ?>.}<br />

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by chunk1978
            i'm clearly getting ahead of myself as i don't really understand... ok... so the code below is a perfect example of what i mean exactly...

            HTML form:
            Code:
            <html>
            <body>
            <form action="phpscript.php" method="post">
            Name: <input type="text" name="name" style="display:none"/>
            <input type="submit" />
            </form>
            </body>
            </html>
            PHP script:
            Code:
            <html>
            <body>
            Welcome <?php echo $_POST["name"]; ?>.<br />
            </body>
            </html>
            so even if the html isn't displaying the name field, will PHP still print/echo it with the PHP output... or is there a way to write the PHP tag a certain way to tell it that if the HTML field is hidden, don't echo... maybe something like this:

            Code:
            <if (form.name.value = "" || form.name.display.none=true) {<?php echo $_POST["name"]; ?>.}<br />
            Nope.
            The only thing you can tell about a form that has posted to you is the actual address the post came from, and the data that has been posted (i.e. the values of the fields).
            However, you could have an input of type HIDDEN that gets changed via Javascript to reflect whether the field is visible, and post that along with the form.

            Comment

            • chunk1978
              New Member
              • Jan 2007
              • 224

              #7
              so what your saying is that if the HTML was written like this:

              Code:
              <html>
              <body>
              <form action="phpscript.php" method="post">
              Name: <input type="text" name="name" style="hidden"/>
              <input type="submit" />
              </form>
              </body>
              </html>
              and if javascript didn't change the hidden field (hidden=true) by the time the form is submitted to the PHP script, than a <?PHP tag on the name file wouldn't echo anything?

              Comment

              Working...