How to port vertical tabs functionality for custom node module to Drupal 7? I have a custom module (written for Drupal 6) which defines a new content type. In Drupal 6 I have used several fieldsets and Vertical Tabs module to have the custom node form more clearly laid out. It looked like this

$form['event'] = array(
    '#type' =&gt; 'fieldset',
    '#title' =&gt;  t('Event'),
    '#weight' =&gt; -2,
);


While porting that module to Drupal 7, I altered that section to use the now-in-core functionality to

M$form['event'] = array(
    '#type' =&gt; 'fieldset',
    '#title' =&gt;  t('Event'),
    '#weight' =&gt; -2,
    '#group' =&gt; 'vt_event',
    '#collapsed' =&gt; true,
    '#collapsible' =&gt; true,
);
$form['vt_event'] = array(
    '#type' =&gt; 'vertical_tabs',
);


This indeed works just fine, when converting up to three fieldsets to the new structure. However, my form is more complex and I need at least five additional fieldsets. But as soon as I convert the fourth fieldset to enable it for vertical tabs, I suddenly get 500 server errors.

Does anyone have any idea why this is happening? It's always the fourth fieldset when it breaks the site and it's regardless which fieldset is the fourth (I tried to enable three other fieldsets first, but again it breaks on the fourth one which worked before).
While driving me nuts yesterday, I started over again today and cleaned up the module a bit.
During that I tried to add another vertical tab again (#4) and this time it worked. By accident, I did re-use a group name and by this I finally was getting fully aware of how this is intended to work.

My mistake was to create a form element of type "vertical_tabs" for each first-level fieldset. But it is sufficient to only have on "vertical_tabs" form element and assign all fieldsets to that group (they actually are grouped then).

So, everything is fine with my code above but the last three lines are only required once.