Here is the code in a simple custom module that I've written:
function new_password_form_alter(&$form, $form_state, $form_id) {
// Check for the right form
if ('user_profile_form' == $form_id) {
unset($form['account']['pass']['pass1']['#title']);
unset($form['account']['pass']['pass2']['#title']);
$form['account']['pass']['pass1']['#title'] = t('New password');
$form['account']['pass']['pass2']['#title'] = t('Confirm new password');
}
}
My problem is, it doesn't work. I think the expand_password_confirm($element) function in form.inc is executed after the custom module executes. Thus, my changes don't take affect.
Basically, this simple module is supposed to change the 'Password:' title to 'New password:' and the 'Confirm password:' title to 'Confirm new password:'.
I can change any other title on this page except these two. Am I doing something wrong? Is there an alternate way of doing this?
I know that the 'String overrides' module can accomplish this, but it also changes the same labels on the 'Add User' form. So, that doesn't work well for me.
Any help you can offer would be appreciated.
Comments
Comment #1
Timothy Robb CreditAttribution: Timothy Robb commented$20 donation to Drupal in honor of whoever provides the solution to this dillemma. Thank you.
Comment #2
brei9000 CreditAttribution: brei9000 commentedDid you find a solution to your problem?
I'm trying to do the same.
Comment #3
chrisyates CreditAttribution: chrisyates commentedTo override the properties of the
pass1
andpass2
, you need to add an additional#process
handler that runs after FAPI'sexpand_password_confirm
, like so:Credit to boaz's blog post for pointing me in the right direction on this.
Comment #4
agileadamAwesome! This was just what I needed... helps me understand the element processing/expansion too :)
Thanks chrisyates and boaz.
Comment #5
JThan CreditAttribution: JThan commentedHi.
I had this problem also.
I suggest a text change on the password field, because as soon as use form_process_password_confirm you get two password fields and I only see this in places where you want to set a new Password. So why not changing the titles so they say that?
The other advantage would be that you could use the translation feature for the title. In the moment you cannot because you would also overwrite the string in the Login Form also.
Referring to http://api.drupal.org/api/function/form_process_password_confirm/7 we have this in D7:
(D6 is similar, just the function name changed: http://api.drupal.org/api/function/expand_password_confirm/6)
includes/form.inc, line 2146
which could be changed to this:
The changes are just the title fields. I did not make a patch out of this now because I may be overseeing some use cases where this makes no sense. Can someone point there or has any other arguments why the text cannot change?
Thx
JThan
Comment #6
kybermanHi,
I had the same problem and my solution is similar:
Comment #7
aburrows CreditAttribution: aburrows commentedThis worked for me:
Comment #8
Ivanhoe123 CreditAttribution: Ivanhoe123 commentedYes, this works for D7
D6 uses:
expand_password_confirm();
D7 uses:
form_process_password_confirm();
They basically do the same thing, the function has just been renamed in D7.
Comment #9
chanderbhushan CreditAttribution: chanderbhushan commentedComment #10
aburrows CreditAttribution: aburrows commentedchanderbhushan you were missing a ' in the conditional statement
Comment #11
dddave CreditAttribution: dddave commentedComment #12
fonant CreditAttribution: fonant commentedIf you want the default password strength meter in D7, you need to include 'user_form_process_password_confirm' too.
Since these default functions are defined as the default '#process' arguments in system_element_info() for a password_confirm element, you can't just append the additional function to the end of the array, as '#process' we see is usually empty.
To be safe (in case Drupal adds new default process functions, and to allow other modules to add process functions before we get here) we need something like:
Comment #15
prsnjtbarman CreditAttribution: prsnjtbarman commentedThis worked for me.
Comment #16
ZalemCitizen CreditAttribution: ZalemCitizen commentedkyberman (#6): congrats, man.
I just added my custom process function at the end of process functions array (build in core file system.module) and it failed. It didn't occur to me that user_form_process_password_confirm needed to be in last position.
Thanks.
Comment #17
vishal.shirguppi CreditAttribution: vishal.shirguppi commentedWorked for me with a small change. My form array structure -
$form['account']['password']['pass']['#process'] = array('form_process_password_confirm', 'my_module_form_process_password_confirm','user_form_process_password_confirm');
Thanks!
Comment #18
KeeneganFor Drupal 8, I did this :
Comment #19
DashDesai CreditAttribution: DashDesai commentedExtending @Keenegan's suggestion, if anyone is looking for a full code for Drupal 8. Include the following in your custom module:
Comment #20
AlexeiK CreditAttribution: AlexeiK commented@Keenegan and @DashDesai
Thanks a lot! Worked like a charm!
Comment #21
jzavrl CreditAttribution: jzavrl at NDP commentedWas looking through this as well and found (I think) a better solution. For Drupal 8, not sure about D7.
This essentially alters the whole password_confirm element which is used on forms. If you use the form alter approach you would need to think of every form where this might occur. With this approach, if the form is using the password_confirm element, you are already taken care of.
Comment #22
Ralf Eisler CreditAttribution: Ralf Eisler commented@jzavrl
Your solution worked for me in Drupal 8. Thank you!
Comment #23
prsnjtbarman CreditAttribution: prsnjtbarman as a volunteer commented@Kng #18 - This worked fine for drupal 8 registration form alter password field
Comment #24
prsnjtbarman CreditAttribution: prsnjtbarman as a volunteer commentedComment #25
Tunprog@jzavrl
Works for me as well in Drupal 8. Thanks!