You are here

function logintoboggan_form_user_register_form_alter in LoginToboggan 7

Implement hook_form_user_register_form_alter().

Related topics

File

./logintoboggan.module, line 223
LoginToboggan module

Code

function logintoboggan_form_user_register_form_alter(&$form, &$form_state) {

  // Admin created accounts are only validated by the module.
  if (user_access('administer users')) {
    $form['#validate'][] = 'logintoboggan_user_register_validate';
    return;
  }
  $mail = variable_get('logintoboggan_confirm_email_at_registration', 0);
  $pass = !variable_get('user_email_verification', TRUE);

  // Ensure a valid submit array.
  $form['#submit'] = is_array($form['#submit']) ? $form['#submit'] : array();

  // Replace core's registration function with LT's registration function.
  // Put the LT submit handler first, so other submit handlers have a valid
  // user to work with upon registration.
  $key = array_search('user_register_submit', $form['#submit']);
  if ($key !== FALSE) {
    unset($form['#submit'][$key]);
  }
  array_unshift($form['#submit'], 'logintoboggan_user_register_submit');
  if ($mail || $pass) {
    $form['#validate'][] = 'logintoboggan_user_register_validate';

    //Display a confirm e-mail address box if option is enabled.
    if ($mail) {
      $form['account']['conf_mail'] = array(
        '#type' => 'textfield',
        '#title' => t('Confirm e-mail address'),
        '#weight' => -28,
        '#maxlength' => 64,
        '#description' => t('Please re-type your e-mail address to confirm it is accurate.'),
        '#required' => TRUE,
      );

      // Weight things properly so that the order is name, mail, conf_mail.
      $form['account']['name']['#weight'] = -30;
      $form['account']['mail']['#weight'] = -29;
    }
    $min_pass = variable_get('logintoboggan_minimum_password_length', 0);
    if ($pass && $min_pass > 0) {
      $form['account']['pass']['#description'] = isset($form['account']['pass']['#description']) ? $form['account']['pass']['#description'] . " " : "";
      $form['account']['pass']['#description'] .= t('Password must be at least %length characters.', array(
        '%length' => $min_pass,
      ));
    }
  }
}