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.
function customization_form_user_register_form_alter(&$form, &$form_state, $form_id) {
 $form['account']['pass']['#attributes']['placeholder'] = t('Password');
}

I am trying to set placeholder on password field in registration form.

I seted placeholder on username and email, but on password field won't work...

Any help? Thank you!

share|improve this question
add comment

1 Answer

Wish I'd seen this sooner. You've probably moved on from this problem, but for the benefit of other people seeking an answer to this question: (obviously replace mymodule with the name of your module)

/**
* Implementation of hook_element_info_alter ()
*/
function mymodule_element_info_alter (& $type)
{
  if (isset($type['password_confirm']['#process'])) {
    $func = '_mymodule_process_password_confirm';

    $type['password_confirm']['#process'][] = $func;
  }

  return $type;
}

/**
 * Do a bit of processing for the password_confirm element.
 * Original processing happens in expand_password_confirm()
 */
function _mymodule_process_password_confirm ($element)
{
  $element['pass1']['#attributes']['placeholder'] = t('Password');
  $element['pass2']['#attributes']['placeholder'] = t('Confirm password');

  // Remove these lines if you want to keep the field labels
  unset($element['pass1']['#title']);
  unset($element['pass2']['#title']);

  return $element;
}
share|improve this answer
    
Thanks for this - worked a treat. –  danbohea May 20 '13 at 13:16
    
De nada. Glad to hear it –  turibe May 22 '13 at 20:36
add comment

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.