-
Hiding fieldsets in a form using hook_form_alter()
The following examples shows how to hide fields/fieldsets in forms using hook_form_alter(). I suggest using the devel module to determine how to target your field(s) or fieldset(s). You can add a dpm($form) to the function during development and testing.
12345678910111213<?phpfunction mymodule_form_alter(&$form, $form_state, $form_id) {global $user;// "hide" a few fieldsets for non-admins// (the lead developer only wants UID 1 to see these fields; I suggest doing it by role though!)// Note that you can also check out the $form_id variable for a different way to which form this isif ($form['#id'] == 'node-form' && $user->uid != 1) {$form['author']['#access'] = FALSE;$form['revision_information']['#access'] = FALSE;}}?>Note that this will prevent the value from being submitted. If you need the value to be included in the submission, you’re better off doing something like this: http://stackoverflow.com/questions/4461237/how-to-hide-a-field-in-a-drupal-form/5308924#5308924