You are here

function user_registrationpassword_form_user_register_form_alter in User registration password 7

Same name and namespace in other branches
  1. 8 user_registrationpassword.module \user_registrationpassword_form_user_register_form_alter()

Implements hook_form_FORM_ID_alter().

See also

user_register_form()

user_registrationpassword_form_user_register_submit()

File

./user_registrationpassword.module, line 231
Enables password creation on registration form.

Code

function user_registrationpassword_form_user_register_form_alter(&$form, &$form_state) {
  global $user;

  // Add the password field from the user_account_form when visitors can
  // register, but require admin approval.
  if (variable_get('user_register', USER_REGISTER_VISITORS) == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL && variable_get('user_registrationpassword_registration', USER_REGISTRATIONPASSWORD_VERIFICATION_DEFAULT) == USER_REGISTRATIONPASSWORD_VERIFICATION_PASS && !$user->uid) {
    $form['account']['pass'] = array(
      '#type' => 'password_confirm',
      '#size' => 25,
      '#description' => t('Provide a password for the new account in both fields.'),
      '#required' => TRUE,
    );
  }

  // Prevent this from being run if approval with password on registration
  // form is set and the user is an anonymous user registering to the site.
  // When admin users create a user, this does not need to be executed.
  // And when this also does not need to be executed 'user_register' is not set
  // as 'Visitors can create accounts and no administrator approval is
  // required.' User registers, recieves user_registrationpass email, would
  // not make sense. Cause that will unblock the user Without
  // the admin 'approving'.
  if (variable_get('user_register', USER_REGISTER_VISITORS) == USER_REGISTER_VISITORS && variable_get('user_registrationpassword_registration', USER_REGISTRATIONPASSWORD_VERIFICATION_DEFAULT) == USER_REGISTRATIONPASSWORD_VERIFICATION_PASS && !$user->uid) {

    // Set the user account to blocked.
    $form['account']['status']['#default_value'] = 0;

    // Supress any notification.
    $form['account']['notify']['#default_value'] = FALSE;

    // Register our validate and submit handlers.
    $form['#submit'][] = 'user_registrationpassword_form_user_register_submit';
  }
}