7

I want to remove password confirmation field. Its ok if user enters the password only once. There is no need to confirm it again.

I am using this code

<?php
function dp_form_alter(&$form, &$form_state, $form_id)  {
    switch ($form_id)  {
        case 'user-register-form': 
        $form['account']['pass']['#type'] = "password"; 
            break;
     }
  }

Please tell me where am I wrong. Its not working. :(

12

The following code works for me in Drupal 7.

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
    $form['account']['pass']['#type'] = 'password';
    $form['account']['pass']['#title'] = 'Password';
}

Please note that the user registration form and the user profile form both have password confirmation fields and are not the same form. You will need to alter both forms if you wish to remove all password confirmation fields.

1

My solution which covers both forms and creates also accurate description.

/**
 * Implements hook_form_alter().
 */
function MYMODULE_login_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
    $form['account']['pass']['#type'] = 'password';
    $form['account']['pass']['#title'] = 'Password';
    $form['account']['pass']['#description'] =  t('To change the current user password, enter the new password.');
    if ($form_id == 'user_register_form') {
      $form['account']['pass']['#description'] =  t('Provide a password for the new account.');
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.