I've searched all over drupal.org for this - Sorry if this is a dupe, I can't believe I'm the first to spot it. it's cosmetic, so not really a big deal.
When asking for a password confirmation (such as when and admin is creating a new user), the password boxes are not marked with a "*" on screen, but are correctly validated by the Forms API as required fields. (Ordinary password fields (such as shown during logon) are correctly marked).
The code that follows demonstrates the problem. You can see it in action by visiting admin/user/user/create as the site admin on your own site (note how username, email etc are marked with a "*" yet password/confirm is not)
$form['account']['pass'] = array(
'#type' => 'password_confirm',
'#description' => t('Provide a password for the new account in both fields.'),
'#required' => TRUE,
'#size' => 25,
);
Incidentally, all validation by Forms API seems to work correctly, it's just not marked correctly in HTML output.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | form_pw_patch.txt | 639 bytes | coofercat |
| #1 | form.inc__0.patch | 569 bytes | tostinni |
Comments
Comment #1
tostinni commentedWhat's happening there is that in this case, the password field is rewritten to be expanded and to display 2 textfield to put both password and confirmation.
Looking at
expand_password_confirmfunction, I think it should also take care of the #required attribute which it doesn't.So I added this part and I think it solves the problem.
Comment #2
coofercat commentedLooks good to me - both boxes marked with a "*". However, there are typos in your patch. It should be:
(You're missing some single quotes after each #required). Otherwise, all good. Updated patch attached.
Comment #3
tostinni commentedUps... my editor eat the quotes... thanks for the review.
Note that the "*" only appears when password is really needed (ie when creating new user), if you're just updating a user, it's optional.
Comment #4
dries commentedCoding style: we'll want to write that in two lines, rather than on one line with two assignments.
Why do we assign
$element['#required']rather than TRUE?Also, what code is currently checking that the password field is required? Can it be simplified when we was in the required attribute? With the required attribute, the form API should take care of this, rather than any _validate callbacks.
Comment #5
tostinni commentedI just copy/modify the same code used to set the #size attribute.
The validation is done by
password_confirm_validateBut I'm not very sure how to take care of this without any _validate callbacks, my knowledge of form API is very very limited...
Comment #6
drummThis has already been fixed:
http://drupal.org/node/136067