Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Is it possible to add a title attribute through a form_alter to element #type 'password_confirm'?

For example, I have a form with the following fields:

  • email
  • password
  • password confirm

To apply a title attribute to the email element is fine...

$form['account']['mail']['#attributes']['title'] = 'enter your email address';

When I dump the contents of $form in search for the input elements for 'password_confirm', I only get the following:

[pass] => Array
                (
                    [#type] => password_confirm
                    [#size] => 25
                    [#description] => We will not spam you or give your email address to third parties.
                    [#required] => 1
                )

I'm not seeing 'pass1' and 'pass2' in the array.

Please could someone point me in the right direction?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The password confirm element is converted to two fields in a process function (form_process_password_confirm()), so adding your own process function to the password element would do the trick.

Per this issue it seems you actually need to overwrite the existing #process array instead of just appending to it, e.g for the user register form password element:

function MYMODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  $form['account']['pass']['#process'] = array(
    'form_process_password_confirm',
    'MYMODULE_password_confirm_process',
    'user_form_process_password_confirm'
  );
}

function MYMODULE_password_confirm_process($element) {
  $element['pass1']['#attributes']['title'] = 'Title';
  $element['pass2']['#attributes']['title'] = 'Title2';
  return $element;
}
share|improve this answer
    
"adding your own process function to the password element would do the trick", this I didnt know possible, incredible! Many many thanks Clive. –  Alex Gill Jun 28 '13 at 16:28

In my case with drupal 7, I corrected with:

function MYMODULE_password_confirm_process($element) {
  $element['pass1']['#title'] = 'Title';
  $element['pass2']['#title'] = 'Title2';
  return $element;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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