=== modified file 'includes/form.inc'
--- includes/form.inc	
+++ 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_values_set($form, $form['#value']);
   }
 
   // Recurse through all child elements.
@@ -437,6 +434,38 @@ function form_builder($form_id, $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_values_set($form, $value) {
+  global $form_values;
+  _form_values_set($form_values, $form, $form['#parents'], $value);
+}
+
+function _form_values_set(&$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_values_set($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
  * called from within a theme.  To render a form from within a module, use
@@ -566,7 +595,8 @@ function theme_select($element) {
   $select = '';
   $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
   _form_set_class($element, array('form-select'));
-  return theme('form_element', $element['#title'], '<select name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size .'>'. form_select_options($element) .'</select>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+  $multiple = isset($element['#multiple']) && $element['#multiple'];
+  return theme('form_element', $element, '<select name="'. $element['#name'] .''. ($multiple ? '[]' : '') .'"'. ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size .'>'. form_select_options($element) .'</select>');
 }
 
 function form_select_options($element, $choices = NULL) {
@@ -618,7 +648,6 @@ function theme_fieldset($element) {
   }
 
   return '<fieldset' . drupal_attributes($element['#attributes']) .'>' . ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . ($element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . $element['#children'] . $element['#value'] . "</fieldset>\n";
-
 }
 
 /**
@@ -640,7 +669,9 @@ function theme_radio($element) {
   if (!is_null($element['#title'])) {
     $output = '<label class="option">'. $output .' '. $element['#title'] .'</label>';
   }
-  return theme('form_element', NULL, $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+
+  unset($element['#title']);
+  return theme('form_element', $element, $output);
 }
 
 /**
@@ -654,7 +685,7 @@ function theme_radio($element) {
  */
 function theme_radios($element) {
   if ($element['#title'] || $element['#description']) {
-    return theme('form_element', $element['#title'], $element['#children'], $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+    return theme('form_element', $element, $element['#children']);
   }
   else {
     return $element['#children'];
@@ -671,7 +702,7 @@ function theme_radios($element) {
  *   A themed HTML string representing the form item.
  */
 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));
+  return theme('form_element', $element, '<div class="container-inline">'. $element['#children']. '</div>');
 }
 
 /**
@@ -681,14 +712,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_values_set($form['pass1'], NULL);
+    form_values_set($form['pass2'], NULL);
+    form_values_set($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.'));
@@ -706,8 +737,7 @@ function password_confirm_validate($form
  *   A themed HTML string representing the date selection boxes.
  */
 function theme_date($element) {
-  $output = '<div class="container-inline">' . $element['#children'] . '</div>';
-  return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+  return theme('form_element', $element, '<div class="container-inline">' . $element['#children'] . '</div>');
 }
 
 /**
@@ -813,7 +843,7 @@ function expand_radios($element) {
  *   A themed HTML string representing the form item.
  */
 function theme_item($element) {
-  return theme('form_element', $element['#title'], $element['#value'] . $element['#children'], $element['#description'], $element['#id'], $element['#required'], $element['#error']);
+  return theme('form_element', $element, $element['#value'] . $element['#children']);
 }
 
 /**
@@ -839,7 +869,8 @@ function theme_checkbox($element) {
     $checkbox = '<label class="option">'. $checkbox .' '. $element['#title'] .'</label>';
   }
 
-  return theme('form_element', NULL, $checkbox, $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+  unset($element['#title']);
+  return theme('form_element', $element, $checkbox);
 }
 
 /**
@@ -852,7 +883,7 @@ function theme_checkbox($element) {
  */
 function theme_checkboxes($element) {
   if ($element['#title'] || $element['#description']) {
-    return theme('form_element', $element['#title'], $element['#children'], $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+    return theme('form_element', $element, $element['#children']);
   }
   else {
     return $element['#children'];
@@ -924,7 +955,7 @@ function theme_textfield($element) {
   }
   _form_set_class($element, $class);
   $output = '<input type="text" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size .' value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) .' />';
-  return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element)). $extra;
+  return theme('form_element', $element, $output). $extra;
 }
 
 /**
@@ -960,7 +991,7 @@ function theme_textarea($element) {
 
   $cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : '';
   _form_set_class($element, $class);
-  return theme('form_element', $element['#title'], '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="' . $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+  return theme('form_element', $element, '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="' . $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>');
 }
 
 /**
@@ -970,7 +1001,7 @@ function theme_textarea($element) {
  *
  * @param $element
  *   An associative array containing the properties of the element.
- *   Properties used: prefix, value, children and suffix.
+ *   Properties used: value, children.
  * @return
  *   A themed HTML string representing the HTML markup.
  */
@@ -993,8 +1024,8 @@ function theme_password($element) {
 
   _form_set_class($element, array('form-text'));
   $output = '<input type="password" maxlength="'. $element['#maxlength'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. $size . drupal_attributes($element['#attributes']) .' />';
-
-  return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+b
+  return theme('form_element', $element, $output);
 }
 
 /**
@@ -1037,7 +1068,43 @@ function theme_weight($element) {
  */
 function theme_file($element) {
   _form_set_class($element, array('form-file'));
-  return theme('form_element', $element['#title'], '<input type="file" name="'. $element['#name'] .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '') .' id="'. form_clean_id($element['#id']) .'" size="'. $element['#size'] ."\" />\n", $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+  return theme('form_element', $element, '<input type="file" name="'. $element['#name'] .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '') .' id="'. form_clean_id($element['#id']) .'" size="'. $element['#size'] ."\" />\n");
+}
+
+/**
+ * Return a themed form element.
+ *
+ * @param element
+ *   An associative array containing the properties of the element.
+ *   Properties used: title, description, id, required
+ * @param $value
+ *   the form element's data
+ * @return
+ *   a string representing the form element
+ */
+function theme_form_element($element, $value) {
+  $output  = '<div class="form-item">'."\n";
+  $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';
+
+  if (!empty($element['#title'])) {
+    $title = $element['#title'];
+    if (!empty($element['#id'])) {
+      $output .= ' <label for="'. form_clean_id($element['#id']) .'">'. $title .":$required</label>\n";
+    }
+    else {
+      $output .= ' <label>'. $title .":$required</label>\n";
+    }
+  }
+
+  $output .= " $value\n";
+
+  if (!empty($element['#description'])) {
+    $output .= ' <div class="description">'. $element['#description'] ."</div>\n";
+  }
+
+  $output .= "</div>\n";
+
+  return $output;
 }
 
 /**
=== modified file 'includes/theme.inc'
--- includes/theme.inc	
+++ includes/theme.inc	
@@ -599,43 +599,6 @@ function theme_node($node, $teaser = FAL
 }
 
 /**
- * Return a themed form element.
- *
- * @param $title the form element's title
- * @param $value the form element's data
- * @param $description the form element's description or explanation
- * @param $id the form element's ID used by the &lt;label&gt; tag
- * @param $required a boolean to indicate whether this is a required field or not
- * @param $error a string with an error message filed against this form element
- *
- * @return a string representing the form element
- */
-function theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
-
-  $output  = '<div class="form-item">'."\n";
-  $required = $required ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';
-
-  if ($title) {
-    if ($id) {
-      $output .= ' <label for="'. form_clean_id($id) .'">'. $title .":$required</label>\n";
-    }
-    else {
-      $output .= ' <label>'. $title .":$required</label>\n";
-    }
-  }
-
-  $output .= " $value\n";
-
-  if ($description) {
-    $output .= ' <div class="description">'. $description ."</div>\n";
-  }
-
-  $output .= "</div>\n";
-
-  return $output;
-}
-
-/**
  * Return a themed submenu, typically displayed under the tabs.
  *
  * @param $links
=== modified file 'modules/node.module'
--- modules/node.module	
+++ modules/node.module	
@@ -2169,7 +2169,7 @@ function node_form_alter($form_id, &$for
  */
 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'])) {
@@ -2179,6 +2179,7 @@ function node_search_validate($form_id, 
       $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']));
   }
@@ -2196,7 +2197,7 @@ function node_search_validate($form_id, 
     $keys .= ' "'. str_replace('"', ' ', $form_values['phrase']) .'"';
   }
   if (!empty($keys)) {
-    $form['basic']['inline']['processed_keys']['#ref'] = trim($keys);
+    form_values_set($form['basic']['inline']['processed_keys'], trim($keys));
   }
 }
 
=== modified file 'modules/search.module'
--- modules/search.module	
+++ modules/search.module	
@@ -1006,7 +1006,7 @@ function search_form($action = '', $keys
  * search form.
  */
 function search_form_validate($form_id, $form_values, $form) {
-  $form['basic']['inline']['processed_keys']['#ref'] = trim($form_values['keys']);
+  form_values_set($form['basic']['inline']['processed_keys'], trim($form_values['keys']));
 }
 
 /**
