Easily hide Drupal fieldset group from forms

First, hook into your existing form, find your Form ID.

/**
* Implements hook_form_FORM_ID_alter().
*/
function YOUR_MODULE_form_FORM_ID_alter(&$form, &$form_state) {
  $form['#after_build'][] = 'YOUR_MODULE_form_FORM_ID_after_build';
}

Replace MACHINE_NAME with your fieldset group machine name.

function YOUR_MODULE_form_FORM_ID_after_build(&$form, &$form_state) {
  // Hide the B2B group.
  field_group_hide_field_groups($form, array('group_MACHINE_NAME'));

  return $form;
}

Remember to clear your Drupal cache for this to work!

4 comments for 'Easily hide Drupal fieldset group from forms'

PROMES's picture

To hide the B2B group you use an unknown function: field_group_hide_field_groups(). Did you create it yourself? It's not in the Drupal functions list for D6, D7 or D8.

Gbirch's picture

Can't you just call field_group_hide_field_groups() directly from form_alter()?

admin's picture

Because in my case, some other modules hook into the after_build() to change the form.

If form_alter() works for you then its good! :)

Add new comment