Index: includes/common.inc
===================================================================
--- includes/common.inc	(revision 99)
+++ includes/common.inc	(working copy)
@@ -2112,6 +2112,25 @@
     return NULL;
   }
 
+  // If the default values for this element haven't been loaded yet, populate 
+  // them.
+  if (!isset($elements['#defaults_loaded']) || !$elements['#defaults_loaded']) {
+    if ((!empty($elements['#type'])) && ($info = _element_info($elements['#type']))) {
+      $elements += $info;
+    }
+  }
+
+  // Make any final changes to the element before it is rendered. This means
+  // that the $element or the chilren can be altered or corrected before the
+  // element is rendered into the final text.
+  if (isset($elements['#pre_render'])) {
+    foreach ($elements['#pre_render'] as $function) {
+      if (function_exists($function)) {
+        $elements = $function($elements);
+      }
+    }
+  }
+
   $content = '';
   // Either the elements did not go through form_builder or one of the children
   // has a #weight.
@@ -2162,6 +2181,16 @@
   }
 
   if (isset($content) && $content !== '') {
+    // Filter the outputed content and make any last changes before the
+    // content is sent to the browser. The changes are made on $content
+    // which allows the output'ed text to be filtered.
+    if (isset($elements['#post_render'])) {
+      foreach ($elements['#post_render'] as $function) {
+        if (function_exists($function)) {
+          $content = $function($content, $elements);
+        }
+      }
+    }
     $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
     $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
     return $prefix . $content . $suffix;
Index: includes/form.inc
===================================================================
--- includes/form.inc	(revision 99)
+++ includes/form.inc	(working copy)
@@ -462,14 +462,6 @@
     }
   }
 
-  if (isset($form['#pre_render'])) {
-    foreach ($form['#pre_render'] as $function) {
-      if (function_exists($function)) {
-        $function($form_id, $form);
-      }
-    }
-  }
-
   $output = drupal_render($form);
   return $output;
 }
@@ -639,6 +631,7 @@
     // overlay $info onto $form, retaining preexisting keys in $form
     $form += $info;
   }
+  $form['#defaults_loaded'] = TRUE;
 
   if (isset($form['#input']) && $form['#input']) {
     if (!isset($form['#name'])) {
