From b354396b69ab75f56e609e6145fd24a46fdb56ba Mon Sep 17 00:00:00 2001
From: Gerhard Killesreiter <killes_www_drop_org@227.no-reply.drupal.org>
Date: Thu, 20 Apr 2006 16:35:29 +0000
Subject: [PATCH] #59528, password_confirm fields don't highlight errors, patch
 by sammys

---
 includes/form.inc            | 17 ++++++++++++++---
 modules/system.module        |  7 +------
 modules/system/system.module |  7 +------
 3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/includes/form.inc b/includes/form.inc
index 4c77f9c59f19..5aef91b19564 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -713,6 +713,18 @@ function theme_password_confirm($element) {
   return theme('form_element', $element['#title'], '<div class="container-inline">'. $element['#children']. '</div>', $element['#description'],  $element['#id'], $element['#required'], form_get_error($element));
 }
 
+/*
+ * Expand a password_confirm field into two text boxes.
+ */
+function expand_password_confirm($element) {
+  $element['pass1'] =  array('#type' => 'password', '#size' => 12, '#value' => $element['#value']['pass1']);
+  $element['pass2'] =  array('#type' => 'password', '#size' => 12, '#value' => $element['#value']['pass2']);
+  $element['#validate'] = array('password_confirm_validate' => array());
+  $element['#tree'] = TRUE;
+
+  return $element;
+}
+
 /**
  * Validate password_confirm element.
  */
@@ -725,13 +737,12 @@ function password_confirm_validate($form) {
     form_set_value($form, $pass1);
     if ($pass1 != $pass2) {
       form_error($form, t('The specified passwords do not match.'));
-      form_error($form['pass1']);
-      form_error($form['pass2']);
     }
   }
   elseif ($form['#required'] && !empty($_POST['edit'])) {
-    form_set_error('pass1', t('Password field is required.'));
+    form_error($form, t('Password field is required.'));
   }
+
   return $form;
 }
 
diff --git a/modules/system.module b/modules/system.module
index 4763534c2c0a..3e4c098deefb 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -63,12 +63,7 @@ function system_elements() {
   $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#form_submitted' => FALSE);
   $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE);
   $type['password'] = array('#input' => TRUE, '#size' => 30);
-  $type['password_confirm'] = array('#input' => TRUE,
-    '#value' => 'pass',
-    'pass1' => array('#type' => 'password', '#size' => 12),
-    'pass2' => array('#type' => 'password', '#size' => 12),
-    '#validate' => array('password_confirm_validate' => array()),
-  );
+  $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm' => array()));
   $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5);
   $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios' => array()));
   $type['radio'] = array('#input' => TRUE);
diff --git a/modules/system/system.module b/modules/system/system.module
index 4763534c2c0a..3e4c098deefb 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -63,12 +63,7 @@ function system_elements() {
   $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#form_submitted' => FALSE);
   $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE);
   $type['password'] = array('#input' => TRUE, '#size' => 30);
-  $type['password_confirm'] = array('#input' => TRUE,
-    '#value' => 'pass',
-    'pass1' => array('#type' => 'password', '#size' => 12),
-    'pass2' => array('#type' => 'password', '#size' => 12),
-    '#validate' => array('password_confirm_validate' => array()),
-  );
+  $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm' => array()));
   $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5);
   $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios' => array()));
   $type['radio'] = array('#input' => TRUE);
-- 
GitLab