Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.655
diff -u -p -r1.655 common.inc
--- includes/common.inc	15 Jun 2007 07:15:24 -0000	1.655
+++ includes/common.inc	17 Jun 2007 12:37:45 -0000
@@ -2550,6 +2550,25 @@ function drupal_render(&$elements) {
     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.
@@ -2601,6 +2620,16 @@ function drupal_render(&$elements) {
   }
 
   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;
@@ -3132,4 +3161,3 @@ function watchdog_severity_levels() {
     WATCHDOG_DEBUG    => t('debug'),
   );
 }
-
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.205
diff -u -p -r1.205 form.inc
--- includes/form.inc	8 Jun 2007 12:51:58 -0000	1.205
+++ includes/form.inc	17 Jun 2007 12:37:48 -0000
@@ -708,6 +708,7 @@ function form_builder($form_id, $form, &
     // Overlay $info onto $form, retaining preexisting keys in $form.
     $form += $info;
   }
+  $form['#defaults_loaded'] = TRUE;
 
   if (isset($form['#input']) && $form['#input']) {
     _form_builder_handle_input_element($form_id, $form, $form_state);
