diff --git a/includes/form.inc b/includes/form.inc
index 052d9ea4624d8d702ee9551021f700567d141512..27120901d8808257189147cd1bcf89adc18eb8d7 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -333,12 +333,9 @@ function form_builder($form_id, $form) {
 
     $posted = (isset($_POST['edit']) && ($_POST['edit']['form_id'] == $form_id));
     $edit = $posted ? $_POST['edit'] : array();
-    $ref =& $form_values;
     foreach ($form['#parents'] as $parent) {
       $edit = isset($edit[$parent]) ? $edit[$parent] : NULL;
-      $ref =& $ref[$parent];
     }
-    $form['#ref'] = &$ref;
     if (!isset($form['#value']) && !array_key_exists('#value', $form)) {
       if ($posted) {
         switch ($form['#type']) {
@@ -402,7 +399,7 @@ function form_builder($form_id, $form) {
   // We call this after #process gets called so that #process has a
   // chance to update #value if desired.
   if (isset($form['#input']) && $form['#input']) {
-    $ref = $form['#value'];
+    form_set_value($form, $form['#value']);
   }
 
   // Recurse through all child elements.
@@ -436,6 +433,45 @@ function form_builder($form_id, $form) {
   return $form;
 }
 
+/**
+ * Use this function to make changes to form values in the form validate 
+ * phase, so they will be available in the submit phase in $form_values.
+ *
+ * Specifically, if $form['#parents'] is array('foo', 'bar')
+ * and $value is 'baz' then this function will make
+ * $form_values['foo']['bar'] to be 'baz'. 
+ *
+ * @param $form
+ *   The form item. Keys used: #parents, #value
+ * @param $value
+ *   The value for the form item.
+ */
+function form_set_value($form, $value) {
+  global $form_values;
+  _form_set_value($form_values, $form, $form['#parents'], $value);
+}
+
+/**
+ * Helper function for form_set_value().
+ *
+ * We iterate of $parents and create nested arrays for them
+ * in $form_values if needed. Then we insert the value in
+ * the right array.
+ */
+function _form_set_value(&$form_values, $form, $parents, $value) {
+  $parent = array_shift($parents);
+  if (empty($parents)) {
+    $form_values[$parent] = $value;
+  }
+  else {
+    if (!isset($form_values[$parent])) {
+      $form_values[$parent] = array();
+    }
+    _form_set_value($form_values[$parent], $form, $parents, $value);
+  }
+  return $form;
+}
+
 /**
  * Renders a HTML form given a form tree. Recursively iterates over each of
  * the form elements, generating HTML code. This function is usually
@@ -681,14 +717,14 @@ function password_confirm_validate($form) {
   if (isset($form['pass1']['#value'])) {
     $pass1 = trim($form['pass1']['#value']);
     $pass2 = trim($form['pass2']['#value']);
-    $form['pass1']['#ref'] = NULL;
-    $form['pass2']['#ref'] = NULL;
+    form_set_value($form['pass1'], NULL);
+    form_set_value($form['pass2'], NULL);
+    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']);
     }
-    $form['#ref'] = $pass1;
   }
   elseif ($form['#required'] && !empty($_POST['edit'])) {
     form_set_error('pass1', t('Password field is required.'));
diff --git a/modules/node.module b/modules/node.module
index be974062b55521718831804f4256951ed63b9d71..cf8c085a28f63580c8d8c6e0c0eec42a6d551f00 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -2170,7 +2170,7 @@ function node_form_alter($form_id, &$form) {
  */
 function node_search_validate($form_id, $form_values, $form) {
   // Initialise using any existing basic search keywords.
-  $keys = $form['basic']['inline']['processed_keys']['#ref'];
+  $keys = $form_values['processed_keys'];
 
   // Insert extra restrictions into the search keywords string.
   if (isset($form_values['type']) && is_array($form_values['type'])) {
@@ -2180,6 +2180,7 @@ function node_search_validate($form_id, $form_values, $form) {
       $keys = search_query_insert($keys, 'type', implode(',', array_keys($form_values['type'])));
     }
   }
+
   if (isset($form_values['category']) && is_array($form_values['category'])) {
     $keys = search_query_insert($keys, 'category', implode(',', $form_values['category']));
   }
@@ -2197,7 +2198,7 @@ function node_search_validate($form_id, $form_values, $form) {
     $keys .= ' "'. str_replace('"', ' ', $form_values['phrase']) .'"';
   }
   if (!empty($keys)) {
-    $form['basic']['inline']['processed_keys']['#ref'] = trim($keys);
+    form_set_value($form['basic']['inline']['processed_keys'], trim($keys));
   }
 }
 
diff --git a/modules/node/node.module b/modules/node/node.module
index be974062b55521718831804f4256951ed63b9d71..cf8c085a28f63580c8d8c6e0c0eec42a6d551f00 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -2170,7 +2170,7 @@ function node_form_alter($form_id, &$form) {
  */
 function node_search_validate($form_id, $form_values, $form) {
   // Initialise using any existing basic search keywords.
-  $keys = $form['basic']['inline']['processed_keys']['#ref'];
+  $keys = $form_values['processed_keys'];
 
   // Insert extra restrictions into the search keywords string.
   if (isset($form_values['type']) && is_array($form_values['type'])) {
@@ -2180,6 +2180,7 @@ function node_search_validate($form_id, $form_values, $form) {
       $keys = search_query_insert($keys, 'type', implode(',', array_keys($form_values['type'])));
     }
   }
+
   if (isset($form_values['category']) && is_array($form_values['category'])) {
     $keys = search_query_insert($keys, 'category', implode(',', $form_values['category']));
   }
@@ -2197,7 +2198,7 @@ function node_search_validate($form_id, $form_values, $form) {
     $keys .= ' "'. str_replace('"', ' ', $form_values['phrase']) .'"';
   }
   if (!empty($keys)) {
-    $form['basic']['inline']['processed_keys']['#ref'] = trim($keys);
+    form_set_value($form['basic']['inline']['processed_keys'], trim($keys));
   }
 }
 
diff --git a/modules/search.module b/modules/search.module
index 4cc487e4104bf32c0a67630797a221485bd6ebd2..cf4cbc4e91ce678ff6cfdc1234d0d63668804e69 100644
--- a/modules/search.module
+++ b/modules/search.module
@@ -1006,7 +1006,7 @@ function search_form($action = '', $keys = '', $type = NULL, $prompt = NULL) {
  * search form.
  */
 function search_form_validate($form_id, $form_values, $form) {
-  $form['basic']['inline']['processed_keys']['#ref'] = trim($form_values['keys']);
+  form_set_value($form['basic']['inline']['processed_keys'], trim($form_values['keys']));
 }
 
 /**
diff --git a/modules/search/search.module b/modules/search/search.module
index 4cc487e4104bf32c0a67630797a221485bd6ebd2..cf4cbc4e91ce678ff6cfdc1234d0d63668804e69 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -1006,7 +1006,7 @@ function search_form($action = '', $keys = '', $type = NULL, $prompt = NULL) {
  * search form.
  */
 function search_form_validate($form_id, $form_values, $form) {
-  $form['basic']['inline']['processed_keys']['#ref'] = trim($form_values['keys']);
+  form_set_value($form['basic']['inline']['processed_keys'], trim($form_values['keys']));
 }
 
 /**