You are here

function profile2_form_user_register_form_alter in Profile 2 7

Same name and namespace in other branches
  1. 7.2 profile2.module \profile2_form_user_register_form_alter()

Implements hook_form_FORM_ID_alter() for the registration form.

File

./profile2.module, line 462
Support for configurable user profiles.

Code

function profile2_form_user_register_form_alter(&$form, &$form_state) {
  $profile_types = profile2_get_types();
  if (!empty($profile_types)) {
    foreach ($profile_types as $type_name => $profile_type) {
      if (!empty($profile_type->data['registration'])) {
        if (empty($form_state['profiles'][$type_name])) {
          $form_state['profiles'][$type_name] = profile2_create(array(
            'type' => $type_name,
          ));
        }
      }
    }
  }

  // If we have profiles to attach to the registration form - then do it.
  if (!empty($form_state['profiles'])) {
    profile2_attach_form($form, $form_state);

    // Wrap each profile form in a fieldset.
    foreach ($form_state['profiles'] as $type_name => $profile) {
      $form['profile_' . $type_name] += array(
        '#type' => 'fieldset',
        '#title' => check_plain($profile_types[$type_name]
          ->getTranslation('label')),
      );
    }
  }
}