If I want a form input to be hidden, can I use CSS display: none or do I need to use an input type=hidden?
I have a long form and depending on certain parameters, some fields may be hidden. I can either write this pseudocode:
if(input is hidden) {
<input type="hidden" ... />
}
else {
<input type="text" ... />
}
Or I could simply apply a style with display:none
for the fields that I want to be hidden.
The latter is easier, but is there a reason why I would want to use type="hidden"
input fields rather than invisib开发者_如何学Cle regular fields? Is the only issue that people without CSS would see them?
It depends on whether you are filtering output based on some condition such as a logged in user. If this is the case then go for the code in your pseudocode option such like
if($var=='loggedin'):
<input type="text" name="privateFieldName" />
else:
//do not display the field
endif;
If you simply want a hidden field regardless use the html hidden input element
精彩评论