Hi

I am altering my user_register form.

I am using Profile and Simplenews modules, and I want to remove the fieldsets around the Profile and Simplenews fields, but keep the fields themselves.

This will just make my form smaller and simpler.

How can I remove the fieldsets?

I've tried:

$form['fieldset']['#type'] = 'hidden';

and

$form['fieldset'] = NULL;

but both of these hide the fields as well.

Any ideas?

Thanks

Glenn

Comments

nevets’s picture

You would need to move the elements of the fieldset up a level before hiding/removing the fieldset.

jaypan’s picture

Or you may be able to do it by changing the #type to 'markup'.

Contact me to contract me for D7 -> D10/11 migrations.

ricsonhoo’s picture

how about :

foreach ($form['fieldset'] as $key => $value) {
  if(is_array($value)) {
    $form[$key] = $value;
  }
}
unset($form['fieldset']);
teodor.sandu’s picture

Although this thread is pretty old and i'm bumping it, i believe the best way to achieve this is to put this:

$form['{fieldset_name}']['#access']=false;

in your implementation of hook_form_alter, of course replacing {fieldset_name} with your fieldset's name (the key in the $form array)

nasseralikarimi’s picture

Thanks this works so clean

damondt’s picture

Remove the fields from the fieldset with:
unset($form['#group_children']['field_your_field']);
Then remove the field group with:

unset($form['#groups']['group_your_group']);
unset($form['#fieldgroups']['group_your_group'])