Page 1 of 1
Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 7:44 am
by Pavilion
Hello...
I just want to hide an input element using php. After the php script runs, it returns information to the user in an echo. I don't want the user to use an input element until they've confirmed the returned echo information.
So... how do I return some css commands to hide this element along with the echoed information?
Thanks Much:
Pavilion
Re: Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 8:23 am
by Celauran
Could be as simple as having the input's class as a variable. Define a class with display: none and another with display: block (or inline or whatever) and set the variable based on the criteria of your choosing.
Re: Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 9:48 am
by Pavilion
Hello Celauran:
Could be as simple as having the input's class as a variable. Define a class with display: none and another with display: block (or inline or whatever) and set the variable based on the criteria of your choosing.
In principal I understand what you are suggesting. But... defining the variable using html, css, and php is a new concept. Do you know where there might be a tutorial, or example, regarding this strategy?
Thanks again - Pavilion
Re: Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 10:17 am
by Celauran
You define your two CSS classes as normal.
Code: Select all
.hide
{
display: none;
}
.show
{
display: block;
}
In your PHP code, you just need to determine which applies.
Code: Select all
$class = (some condition) ? 'show' : 'hide';
<input type="text" class="<?php echo $class; ?>" etc />
Re: Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 2:58 pm
by Pavilion
Celauran wrote:You define your two CSS classes as normal.
Code: Select all
.hide
{
display: none;
}
.show
{
display: block;
}
In your PHP code, you just need to determine which applies.
Code: Select all
$class = (some condition) ? 'show' : 'hide';
<input type="text" class="<?php echo $class; ?>" etc />
Celauran... THANK YOU!!!!!
I'd found information on using variables with css yesterday, but everything I tried didn't work. Your little demo went a long way towards clarifying things. I'll give it a run tonight, and see if I can make it work in the application.
Pavilion
Re: Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 7:41 pm
by califdon
Do understand this: there are no "if"s in HTML or CSS because they are not logical processing languages, they are just markup languages. PHP is a logical processing language and it is the only thing you can use (other than Javascript, in the browser) to do conditional logic. PHP's function is to determine, before sending anything to the browser, exactly WHAT will be sent to the browser. Think of it that way and you should be able to answer such questions.
Re: Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 9:20 pm
by Pavilion
califdon wrote:Do understand this: there are no "if"s in HTML or CSS because they are not logical processing languages, they are just markup languages. PHP is a logical processing language and it is the only thing you can use (other than Javascript, in the browser) to do conditional logic. PHP's function is to determine, before sending anything to the browser, exactly WHAT will be sent to the browser. Think of it that way and you should be able to answer such questions.
Hello Califdon -
Yes - your observation - is something I have noticed. It's percisely why I've felt so much frustration in getting one single input element to "hide" when returning data from php. But.. Celauran's suggestion should take care of the trick. I'm going to try working with it right now.
Pavilion
Re: Use PHP to hide an <input> element
Posted: Thu Jun 28, 2012 9:56 pm
by Pavilion
Hello Celauran:
Your solution is fantastic. Such a small thing, can make such a big difference.
It's best to show users only what they need to complete a task, and hiding that one input element until a user confirmed data returned by php makes a big difference.
Thanks again:
Pavilion