Auto-collapsing fieldsets on user_profile_form I am following these guides:
Customize the User Edit page in Drupal 7: https://www.drupal.org/node/2279959
Collapsing default fieldsets (Drupal 6): https://www.drupal.org/node/733198

Basically, I just want to make all of the fieldsets on the user_profile_form (e.g. /user/1/edit) collapsed by default.

Here is what I've got so far, but it doesn't work - page never finishes loading (I have changed THEMENAME to the name of my theme).  This still doesn't work however...

function THEMENAME_theme() {
  return array(
    // The form ID.
    'user_profile_form' =&gt; array(
      // Forms always take the form argument.
      'arguments' =&gt; array('form' =&gt; NULL),
      'render element' =&gt; 'form',
    ),
  );
}

function THEMENAME_user_profile_form($form) {
  //Create array to return
  $form_elements = element_children($form);
  foreach ($form_elements as $element) {
    //Identify fieldsets and collapse them
    if ($form[$element]['#type'] == 'fieldset') { 
      $form[$element]['#collapsible'] = TRUE;
      $form[$element]['#collapsed']   = TRUE;
    }
  }
  return drupal_render($form);
}


I have a feeling that there is something that I am missing regarding converting this Drupal 6 code to work with Drupal 7 but I am lost.  I have about 30 tabs open and have searched extensively on stackexchange, drupal.org, etc. to no avail.  Please help!

EDIT: here is the code for a small custom module I wrote to easily test this (no need to clear the cache every time like with template.php)

function collapse_form_alter(&amp;$form, &amp;$form_state, $form_id)
{
    if ($form_id == "user_profile_form")
    {
        $form['edit-picture']['#collapsible'] = true;
        $form['edit-picture']['#collapsed'] = true;
       $form['edit-timezone']['#collapsible'] = true;
        $form['edit-timezone']['#collapsed'] = true;
        // test to make sure module and hook_form_alter is working
        $form['#attributes']['class'][] = 'foo7';
    }
}


I should add that I've tried dashes and underscores, e.g. edit_picture and edit-picture.
You want to use hook_form_alter here.

THEME_form_alter(&amp;$form, &amp;$form_state, $form_id)
{
    if ($form_id == "user_profile_form")
    {
        $form["FIELDSET"]["#collapsible"] = true;
        $form["FIELDSET"]["#collapsed"] = true;
    }
}