I recently needed to alter a standard password_confirm field type in a form that I maintain. Apparently, setting '#maxlength' property on password_confirm form field has no effect. No helpful at all also proved Drupal FAPI official reference (oddly) which has no mention of password_confirm element(!). Anybody who knows why is welcome to hint me.
Anyhow, after some reaserch on this, and a little help from yhager on IRC, I ended up doing it without hacking Drupal code. Here's how:
- Alter the password_confirm form element and put
$form['password'] = array(
'#type' => 'password_confirm',
'#size' => 15,
'#required' => TRUE,
'#process' => array('expand_password_confirm', '<module_name>_pass_confirm_maxlegth'),
);The relevant line is the bold one. Naturally, you can change the second parameter. This parameter is a function name that will be called before the form is rendered.
- Implement the <module_name>_pass_confirm_maxlegth and put in it:
function <module_name>_pass_confirm_maxlegth($element) {
$element['pass1']["#maxlength"] = 10;
$element['pass2']["#maxlength"] = 10;
return $element;
}
Explanation: the default #process entry for password_confirm is the "expand_password_confirm" function which is located in includes/form..inc. We just added another processing function, which runs before the form element is rendered.
I hope this little recipe would be found useful to other.
Boaz.

Thanks yaar
Good Explanation.Thanks Boaz.