You are here

function rpt_form_alter in Registration Password Token 7

Implements hook_form_alter().

File

./rpt.module, line 6

Code

function rpt_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_admin_settings':

      // Add checkbox with setting of password automatic generation.
      $form['registration_cancellation']['rpt_password_generate'] = array(
        '#type' => 'checkbox',
        '#title' => t('Generate password automatically'),
        '#description' => t('Hide password fields on user register form.'),
        '#default_value' => variable_get('rpt_password_generate', 0),
        '#weight' => 0,
      );
      $form['registration_cancellation']['rpt_password_length'] = array(
        '#type' => 'textfield',
        '#title' => t('Password length'),
        '#description' => t('Length for generated password.'),
        '#default_value' => variable_get('rpt_password_length', 10),
        '#weight' => 1,
      );
      foreach ($form as $key => $option) {
        if (is_array($option) && isset($option['#group']) && $option['#group'] == 'email') {
          $form[$key]['#description'] = str_replace('[user:name]', '[user:name], [user:password]', $option['#description']);
        }
      }
      break;
    case 'user_register_form':

      // Hide password field and generate password for user.
      $generate_password = variable_get('rpt_password_generate', 0);
      if ($generate_password) {
        $form['account']['pass']['#type'] = 'value';
        $password_length = variable_get('rpt_password_length', 10);
        $form['account']['pass']['#value'] = user_password($password_length);
      }
      break;
    case 'user_profile_form':
      array_unshift($form['#submit'], 'rpt_user_profile_form_submit');
      break;
  }
}