I want to unset a fieldset programmatically which is available in the content type. I tried to unset like this in hook_form_alter,


But it doesn't work, where as hiding individual fields works in the same format. I tried hide() too , but still it doesn't work.

Any help will be much appreciated and Thanks in advance.


The mentioned solution ['#access'] = false will be a possible solution, but if it's not working you may try:

 * 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;
| improve this answer | |
  • Its still showing the fieldset after adding the hook_form_FORM_ID_alter and _after_build() also. – Ram May 28 '15 at 6:06
  • Is the FORM ID correct may be its not working because of the form id. – Sidharth May 28 '15 at 6:12
  • you can use GET FORM ID module to check that – Sidharth May 28 '15 at 6:17
  • I haven't used the recent version of field groups module and field_group_hide_field_groups() is not available in that version. Now updated the field groups version and seems to be working fine. – Ram May 28 '15 at 6:45

You can try below code :

$form['field_first_deposit']['#access'] = '0';

It will hide the field

| improve this answer | |

The Drupal form API has the #access element for fields that toggles visibility. If you need hide a fieldset, you'll need to do both.

$form['field_first_deposit']['#access'] = false;
| improve this answer | |
  • 1
    I tried that option also and it doesn't seems to be working.Its showing the fieldset. – Ram May 28 '15 at 5:11
  • It looks like you have to do both hide() & #access. – Shawn Conn May 28 '15 at 5:27
  • 1
    Having both also still it doesn't help. – Ram May 28 '15 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.