how to effectively hide a field (with title) on a form 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 &lt;div class='some_class'&gt; (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?
You can set the #access property for the form field to FALSE. The form field will not be shown to the users, but its value will be still be available in $form_state['values'] for the submission, and validation handlers.

Using #access is always the suggested way to avoid users can change the value of a form field, and avoid any third-party module depending on that form field starts to raise warnings, or fails to work as expected.