By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,640 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,640 IT Pros & Developers. It's quick & easy.

PHP with Style="Display:None"?

chunk1978
100+
P: 224
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?
Feb 7 '07 #1
Share this Question
Share on Google+
6 Replies


Motoma
Expert 2.5K+
P: 3,235
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.
Feb 7 '07 #2

chunk1978
100+
P: 224
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?
Feb 7 '07 #3

Motoma
Expert 2.5K+
P: 3,235
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.
Feb 7 '07 #4

chunk1978
100+
P: 224
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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="phpscript.php" method="post">
  4. Name: <input type="text" name="name" style="display:none"/>
  5. <input type="submit" />
  6. </form>
  7. </body>
  8. </html>
  9.  
PHP script:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. Welcome <?php echo $_POST["name"]; ?>.<br />
  4. </body>
  5. </html>
  6.  
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:

Expand|Select|Wrap|Line Numbers
  1. <if (form.name.value = "" || form.name.display.none=true) {<?php echo $_POST["name"]; ?>.}<br />
  2.  
Feb 7 '07 #5

Motoma
Expert 2.5K+
P: 3,235
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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="phpscript.php" method="post">
  4. Name: <input type="text" name="name" style="display:none"/>
  5. <input type="submit" />
  6. </form>
  7. </body>
  8. </html>
  9.  
PHP script:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. Welcome <?php echo $_POST["name"]; ?>.<br />
  4. </body>
  5. </html>
  6.  
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:

Expand|Select|Wrap|Line Numbers
  1. <if (form.name.value = "" || form.name.display.none=true) {<?php echo $_POST["name"]; ?>.}<br />
  2.  
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.
Feb 7 '07 #6

chunk1978
100+
P: 224
so what your saying is that if the HTML was written like this:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="phpscript.php" method="post">
  4. Name: <input type="text" name="name" style="hidden"/>
  5. <input type="submit" />
  6. </form>
  7. </body>
  8. </html>
  9.  
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?
Feb 7 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.