Possible Duplicate:
specify $form elements to be excluded from display?
I would like to hide a field on a form using hook_form_ID_alter
. The form is owned by another module. This field cannot be unset
because it contains a value.
Using CSS {display: none}
for the standard field class is not good because the field should be hidden only in specific conditions (which must be determined using php).
In hook_form_ID_alter
, I could add an #attribute
to the field with a class value e.g. hideme
and then use CSS to hide this class. But it will leave the field title (tried).
The field has #prefix
set to <div class='some_class'>
(in this particular case). This prefix precedes the field as well as the title when displayed in a browser. So I could analyze the prefix with regular expression and add a hideme
class there. But I am not 100% sure what the #prefix will contain, so the regexp could be complex.
Perhaps there is a better way to hide a field with title on a form?