Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.275
diff -u -p -r1.275 form.inc
--- includes/form.inc	25 Jun 2008 09:57:07 -0000	1.275
+++ includes/form.inc	25 Jun 2008 14:31:33 -0000
@@ -85,8 +85,8 @@ function drupal_get_form($form_id) {
     // have to rebuild the form to proceed. In addition, if there is stored
     // form_state data from a previous step, we'll retrieve it so it can
     // be passed on to the form processing code.
-    if (isset($_POST['form_id']) && $_POST['form_id'] == $form_id && !empty($_POST['form_build_id'])) {
-      $form = form_get_cache($_POST['form_build_id'], $form_state);
+    if (isset($_POST['form_id']['#value']) && $_POST['form_id']['#value'] == $form_id && !empty($_POST['form_build_id']['#value'])) {
+      $form = form_get_cache($_POST['form_build_id']['#value'], $form_state);
     }
 
     // If the previous bit of code didn't result in a populated $form
@@ -267,9 +267,9 @@ function form_set_cache($form_build_id, 
  *
  * // register a new user
  * $form_state = array();
- * $form_state['values']['name'] = 'robo-user';
- * $form_state['values']['mail'] = 'robouser@example.com';
- * $form_state['values']['pass'] = 'password';
+ * $form_state['values']['name']['#value'] = 'robo-user';
+ * $form_state['values']['mail']['#value'] = 'robouser@example.com';
+ * $form_state['values']['pass']['#value'] = 'password';
  * $form_state['values']['op'] = t('Create new account');
  * drupal_execute('user_register', $form_state);
  *
@@ -277,9 +277,9 @@ function form_set_cache($form_build_id, 
  * $form_state = array();
  * module_load_include('inc', 'node', 'node.pages');
  * $node = array('type' => 'story');
- * $form_state['values']['title'] = 'My node';
- * $form_state['values']['body'] = 'This is the body text!';
- * $form_state['values']['name'] = 'robo-user';
+ * $form_state['values']['title']['#value'] = 'My node';
+ * $form_state['values']['body']['#value'] = 'This is the body text!';
+ * $form_state['values']['name']['#value'] = 'robo-user';
  * $form_state['values']['op'] = t('Save');
  * drupal_execute('story_node_form', $form_state, (object)$node);
  */
@@ -388,7 +388,7 @@ function drupal_process_form($form_id, &
   $form = form_builder($form_id, $form, $form_state);
   // Only process the form if it is programmed or the form_id coming
   // from the POST data is set and matches the current form_id.
-  if ((!empty($form['#programmed'])) || (!empty($form['#post']) && (isset($form['#post']['form_id']) && ($form['#post']['form_id'] == $form_id)))) {
+  if ((!empty($form['#programmed'])) || (!empty($form['#post']) && (isset($form['#post']['form_id']['#value']) && ($form['#post']['form_id']['#value'] == $form_id)))) {
     drupal_validate_form($form_id, $form, $form_state);
 
     // form_clean_id() maintains a cache of element IDs it has seen,
@@ -405,9 +405,9 @@ function drupal_process_form($form_id, &
       // We'll clear out the cached copies of the form and its stored data
       // here, as we've finished with them. The in-memory copies are still
       // here, though.
-      if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED && !empty($form_state['values']['form_build_id'])) {
-        cache_clear_all('form_' . $form_state['values']['form_build_id'], 'cache_form');
-        cache_clear_all('storage_' . $form_state['values']['form_build_id'], 'cache_form');
+      if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED && !empty($form_state['values']['form_build_id']['#value'])) {
+        cache_clear_all('form_' . $form_state['values']['form_build_id']['#value'], 'cache_form');
+        cache_clear_all('storage_' . $form_state['values']['form_build_id']['#value'], 'cache_form');
       }
 
       // If batches were set in the submit handlers, we process them now,
@@ -466,7 +466,7 @@ function drupal_prepare_form($form_id, &
       '#type' => 'hidden',
       '#value' => $form['#build_id'],
       '#id' => $form['#build_id'],
-      '#name' => 'form_build_id',
+      '#name' => 'form_build_id[#value]',
     );
   }
 
@@ -564,7 +564,7 @@ function drupal_validate_form($form_id, 
   // If the session token was set by drupal_prepare_form(), ensure that it
   // matches the current user's session.
   if (isset($form['#token'])) {
-    if (!drupal_valid_token($form_state['values']['form_token'], $form['#token'])) {
+    if (!drupal_valid_token($form_state['values']['form_token']['#value'], $form['#token'])) {
       // Setting this error will cause the form to fail validation.
       form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
     }
@@ -887,10 +887,12 @@ function form_builder($form_id, $form, &
       // Check to see if a tree of child elements is present. If so,
       // continue down the tree if required.
       $form[$key]['#parents'] = $form[$key]['#tree'] && $form['#tree'] ? array_merge($form['#parents'], array($key)) : array($key);
-      $array_parents = isset($form['#array_parents']) ? $form['#array_parents'] : array();
-      $array_parents[] = $key;
-      $form[$key]['#array_parents'] = $array_parents;
     }
+    // We always want to make sure that the array parents get set here so
+    // that they correctly indicate the structure of the form array.
+    $array_parents = isset($form['#array_parents']) ? $form['#array_parents'] : array();
+    $array_parents[] = $key;
+    $form[$key]['#array_parents'] = $array_parents;
 
     // Assign a decimal placeholder weight to preserve original array order.
     if (!isset($form[$key]['#weight'])) {
@@ -957,6 +959,7 @@ function _form_builder_handle_input_elem
       $form['#name'] .= '[' . implode('][', $form['#parents']) . ']';
     }
     array_unshift($form['#parents'], $name);
+    $form['#name'] .= '[#value]';
   }
   if (!isset($form['#id'])) {
     $form['#id'] = form_clean_id('edit-' . implode('-', $form['#parents']));
@@ -969,16 +972,25 @@ function _form_builder_handle_input_elem
 
   if (!isset($form['#value']) && !array_key_exists('#value', $form)) {
     $function = !empty($form['#value_callback']) ? $form['#value_callback'] : 'form_type_' . $form['#type'] . '_value';
-    if (($form['#programmed']) || ((!isset($form['#access']) || $form['#access']) && isset($form['#post']) && (isset($form['#post']['form_id']) && $form['#post']['form_id'] == $form_id))) {
+    if (($form['#programmed']) || ((!isset($form['#access']) || $form['#access']) && isset($form['#post']) && (isset($form['#post']['form_id']['#value']) && $form['#post']['form_id']['#value'] == $form_id))) {
+      // Traverse the $_POST array to find the form element.
       $edit = $form['#post'];
       foreach ($form['#parents'] as $parent) {
         $edit = isset($edit[$parent]) ? $edit[$parent] : NULL;
       }
+      // If the form element has a posted value (rather than just serving
+      // as a container for other elements), use that.
+      if (isset($edit['#value'])) {
+        $edit = $edit['#value'];
+      }
       if (!$form['#programmed'] || isset($edit)) {
-        // Call #type_value to set the form value;
+        // Obtain the form value from the #value_callback function (if it
+        // exists).
         if (function_exists($function)) {
           $form['#value'] = $function($form, $edit);
         }
+        // Otherwise, use the part of the $_POST array that is associated
+        // with this form element.
         if (!isset($form['#value']) && isset($edit)) {
           $form['#value'] = $edit;
         }
@@ -990,7 +1002,7 @@ function _form_builder_handle_input_elem
     }
     // Load defaults.
     if (!isset($form['#value'])) {
-      // Call #type_value without a second argument to request default_value handling.
+      // Call #value_callback without a second argument to request default value handling.
       if (function_exists($function)) {
         $form['#value'] = $function($form);
       }
@@ -1188,6 +1200,14 @@ function form_type_checkboxes_value($for
   elseif (!isset($edit)) {
     return array();
   }
+  // Return an array of the boxes that were checked.
+  else {
+    $values = array();
+    foreach ($edit as $key => $value) {
+      $values[$key] = $value['#value'];
+    }
+    return $values;
+  }
 }
 
 /**
@@ -1282,7 +1302,7 @@ function form_type_token_value($form, $e
  * of nested values, some care must be taken when using this function.
  * Specifically, $form_item['#parents'] is an array that describes the branch of
  * the tree whose value should be updated. For example, if we wanted to update
- * $form_state['values']['one']['two'] to 'new value', we'd pass in
+ * $form_state['values']['one']['two']['#value'] to 'new value', we'd pass in
  * $form_item['#parents'] = array('one', 'two') and $value = 'new value'.
  *
  * @param $form_item
@@ -1308,7 +1328,7 @@ function form_set_value($form_item, $val
 function _form_set_value(&$form_values, $form_item, $parents, $value) {
   $parent = array_shift($parents);
   if (empty($parents)) {
-    $form_values[$parent] = $value;
+    $form_values[$parent]['#value'] = $value;
   }
   else {
     if (!isset($form_values[$parent])) {
@@ -1391,7 +1411,7 @@ function theme_select($element) {
   $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
   _form_set_class($element, array('form-select'));
   $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>');
+  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>') . (isset($element['#children']) ? $element['#children'] : '');
 }
 
 function form_select_options($element, $choices = NULL) {
@@ -1501,7 +1521,7 @@ function theme_fieldset($element) {
     }
   }
 
-  return '<fieldset' . drupal_attributes($element['#attributes']) . '>' . ($element['#title'] ? '<legend>' . $element['#title'] . '</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') . "</fieldset>\n";
+  return '<fieldset' . drupal_attributes($element['#attributes']) . '>' . ($element['#title'] ? '<legend>' . $element['#title'] . '</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '') . (isset($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') . "</fieldset>\n";
 }
 
 /**
@@ -1527,7 +1547,7 @@ function theme_radio($element) {
   }
 
   unset($element['#title']);
-  return theme('form_element', $element, $output);
+  return theme('form_element', $element, $output) . (isset($element['#children']) ? $element['#children'] : '');
 }
 
 /**
@@ -1825,6 +1845,45 @@ function form_expand_ahah($element) {
 }
 
 /**
+ * Expand a form element by adding an input format selector as its child.
+ */
+function form_expand_input_format($element) {
+  if (isset($element['#input_format']) && $element['#input_format'] !== FALSE) {
+    $parents = isset($element['#parents']) ? $element['#parents'] : array();
+    $weight = 10;
+    $format_selector = filter_form($element['#input_format'], $weight, $parents);
+    form_attach_children($element, $format_selector);
+  }
+  return $element;
+}
+
+/**
+ * Add children to a form element. This allows an arbitrary form element to
+ * be expanded to include a number of other form elements as its children.
+ *
+ * @param $parent
+ *   An associative array containing the structure of the original form
+ *   element.
+ * @param $children
+ *   An associate array containing the structure of the form elements to be
+ *   added as children.
+ */
+function form_attach_children(&$parent, $children) {
+  // We set the parent #tree to TRUE, which is needed in order to cascade
+  // down and have the new children appear in a nested structure by
+  // default. However, we don't want to squash the behavior of any existing
+  // children. So we explicitly set #tree to FALSE for these children if it
+  // is needed to preserve their original behavior.
+  foreach (element_children($parent) as $key) {
+    if (!isset($parent[$key]['#tree']) && isset($parent[$key]['#type']) && $default_elements = _element_info($parent[$key]['#type']) && isset($default_elements['#tree']) && !$default_elements['#tree']) {
+      $parent[$key]['#tree'] = FALSE;
+    }
+  }
+  $parent['#tree'] = TRUE;
+  $parent = $parent + $children;
+}
+
+/**
  * Format a form item.
  *
  * @param $element
@@ -1836,7 +1895,7 @@ function form_expand_ahah($element) {
  * @ingroup themeable
  */
 function theme_item($element) {
-  return theme('form_element', $element, $element['#value'] . (!empty($element['#children']) ? $element['#children'] : ''));
+  return theme('form_element', $element, $element['#value'] . (isset($element['#children']) ? $element['#children'] : ''));
 }
 
 /**
@@ -1865,7 +1924,7 @@ function theme_checkbox($element) {
   }
 
   unset($element['#title']);
-  return theme('form_element', $element, $checkbox);
+  return theme('form_element', $element, $checkbox) . (isset($element['#children']) ? $element['#children'] : '');
 }
 
 /**
@@ -2017,7 +2076,7 @@ function theme_textfield($element) {
     $output .= ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>';
   }
 
-  return theme('form_element', $element, $output) . $extra;
+  return theme('form_element', $element, $output) . $extra . (isset($element['#children']) ? $element['#children'] : '');
 }
 
 /**
@@ -2067,7 +2126,7 @@ function theme_textarea($element) {
   }
 
   _form_set_class($element, $class);
-  return theme('form_element', $element, '<textarea cols="' . $element['#cols'] . '" rows="' . $element['#rows'] . '" name="' . $element['#name'] . '" id="' . $element['#id'] . '" ' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>');
+  return theme('form_element', $element, '<textarea cols="' . $element['#cols'] . '" rows="' . $element['#rows'] . '" name="' . $element['#name'] . '" id="' . $element['#id'] . '" ' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>') . (isset($element['#children']) ? $element['#children'] : '');
 }
 
 /**
@@ -2105,7 +2164,7 @@ function theme_password($element) {
 
   _form_set_class($element, array('form-text'));
   $output = '<input type="password" name="' . $element['#name'] . '" id="' . $element['#id'] . '" ' . $maxlength . $size . drupal_attributes($element['#attributes']) . ' />';
-  return theme('form_element', $element, $output);
+  return theme('form_element', $element, $output) . (isset($element['#children']) ? $element['#children'] : '');
 }
 
 /**
@@ -2145,7 +2204,7 @@ function process_weight($element) {
  */
 function theme_file($element) {
   _form_set_class($element, array('form-file'));
-  return theme('form_element', $element, '<input type="file" name="' . $element['#name'] . '"' . ($element['#attributes'] ? ' ' . drupal_attributes($element['#attributes']) : '') . ' id="' . $element['#id'] . '" size="' . $element['#size'] . "\" />\n");
+  return theme('form_element', $element, '<input type="file" name="' . $element['#name'] . '"' . ($element['#attributes'] ? ' ' . drupal_attributes($element['#attributes']) : '') . ' id="' . $element['#id'] . '" size="' . $element['#size'] . "\" />\n") . (isset($element['#children']) ? $element['#children'] : '');
 }
 
 /**
Index: modules/block/block.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v
retrieving revision 1.18
diff -u -p -r1.18 block.admin.inc
--- modules/block/block.admin.inc	25 Jun 2008 09:52:41 -0000	1.18
+++ modules/block/block.admin.inc	25 Jun 2008 14:31:39 -0000
@@ -262,8 +262,8 @@ function block_admin_configure(&$form_st
 }
 
 function block_admin_configure_validate($form, &$form_state) {
-  if ($form_state['values']['module'] == 'block') {
-    if (empty($form_state['values']['info']) || db_result(db_query("SELECT COUNT(*) FROM {boxes} WHERE bid != %d AND info = '%s'", $form_state['values']['delta'], $form_state['values']['info']))) {
+  if ($form_state['values']['module']['#value'] == 'block') {
+    if (empty($form_state['values']['info']['#value']) || db_result(db_query("SELECT COUNT(*) FROM {boxes} WHERE bid != %d AND info = '%s'", $form_state['values']['delta']['#value'], $form_state['values']['info']['#value']))) {
       form_set_error('info', t('Please ensure that each block description is unique.'));
     }
   }
@@ -271,12 +271,12 @@ function block_admin_configure_validate(
 
 function block_admin_configure_submit($form, &$form_state) {
   if (!form_get_errors()) {
-    db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, title = '%s' WHERE module = '%s' AND delta = '%s'", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $form_state['values']['delta']);
-    db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module'], $form_state['values']['delta']);
-    foreach (array_filter($form_state['values']['roles']) as $rid) {
-      db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']);
+    db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, title = '%s' WHERE module = '%s' AND delta = '%s'", $form_state['values']['visibility']['#value'], trim($form_state['values']['pages']['#value']), $form_state['values']['custom']['#value'], $form_state['values']['title']['#value'], $form_state['values']['module']['#value'], $form_state['values']['delta']['#value']);
+    db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module']['#value'], $form_state['values']['delta']['#value']);
+    foreach (array_filter($form_state['values']['roles']['#value']) as $rid) {
+      db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module']['#value'], $form_state['values']['delta']['#value']);
     }
-    module_invoke($form_state['values']['module'], 'block', 'save', $form_state['values']['delta'], $form_state['values']);
+    module_invoke($form_state['values']['module']['#value'], 'block', 'save', $form_state['values']['delta']['#value'], $form_state['values']);
     drupal_set_message(t('The block configuration has been saved.'));
     cache_clear_all();
     $form_state['redirect'] = 'admin/build/block';
@@ -292,7 +292,7 @@ function block_add_block_form(&$form_sta
 }
 
 function block_add_block_form_validate($form, &$form_state) {
-  if (empty($form_state['values']['info']) || db_result(db_query("SELECT COUNT(*) FROM {boxes} WHERE info = '%s'", $form_state['values']['info']))) {
+  if (empty($form_state['values']['info']['#value']) || db_result(db_query("SELECT COUNT(*) FROM {boxes} WHERE info = '%s'", $form_state['values']['info']['#value']))) {
     form_set_error('info', t('Please ensure that each block description is unique.'));
   }
 }
@@ -301,17 +301,17 @@ function block_add_block_form_validate($
  * Save the new custom block.
  */
 function block_add_block_form_submit($form, &$form_state) {
-  db_query("INSERT INTO {boxes} (body, info, format) VALUES ('%s', '%s', %d)", $form_state['values']['body'], $form_state['values']['info'], $form_state['values']['format']);
+  db_query("INSERT INTO {boxes} (body, info, format) VALUES ('%s', '%s', %d)", $form_state['values']['body']['#value'], $form_state['values']['info']['#value'], $form_state['values']['body']['format']['#value']);
   $delta = db_last_insert_id('boxes', 'bid');
 
   foreach (list_themes() as $key => $theme) {
     if ($theme->status) {
-      db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta, cache) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d)", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $theme->name, 0, 0, $delta, BLOCK_NO_CACHE);
+      db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta, cache) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d)", $form_state['values']['visibility']['#value'], trim($form_state['values']['pages']['#value']), $form_state['values']['custom']['#value'], $form_state['values']['title']['#value'], $form_state['values']['module']['#value'], $theme->name, 0, 0, $delta, BLOCK_NO_CACHE);
     }
   }
 
-  foreach (array_filter($form_state['values']['roles']) as $rid) {
-    db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta);
+  foreach (array_filter($form_state['values']['roles']['#value']) as $rid) {
+    db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module']['#value'], $delta);
   }
 
   drupal_set_message(t('The block has been created.'));
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.307
diff -u -p -r1.307 block.module
--- modules/block/block.module	26 May 2008 17:12:54 -0000	1.307
+++ modules/block/block.module	25 Jun 2008 14:31:40 -0000
@@ -310,29 +310,26 @@ function block_box_form($edit = array())
     '#required' => TRUE,
     '#weight' => -19,
   );
-  $form['body_field']['#weight'] = -17;
-  $form['body_field']['body'] = array(
+
+  $form['body'] = array(
     '#type' => 'textarea',
     '#title' => t('Block body'),
     '#default_value' => $edit['body'],
     '#rows' => 15,
     '#description' => t('The content of the block as shown to the user.'),
     '#weight' => -17,
+    '#input_format' => isset($edit['format']) ? $edit['format'] : FILTER_FORMAT_DEFAULT,
   );
-  if (!isset($edit['format'])) {
-    $edit['format'] = FILTER_FORMAT_DEFAULT;
-  }
-  $form['body_field']['format'] = filter_form($edit['format'], -16);
 
   return $form;
 }
 
 function block_box_save($edit, $delta) {
-  if (!filter_access($edit['format'])) {
-    $edit['format'] = FILTER_FORMAT_DEFAULT;
+  if (!filter_access($edit['body']['format']['#value'])) {
+    $edit['body']['format']['#value'] = FILTER_FORMAT_DEFAULT;
   }
 
-  db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body'], $edit['info'], $edit['format'], $delta);
+  db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body']['#value'], $edit['info']['#value'], $edit['body']['format']['#value'], $delta);
 
   return TRUE;
 }
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.641
diff -u -p -r1.641 comment.module
--- modules/comment/comment.module	20 Jun 2008 16:52:55 -0000	1.641
+++ modules/comment/comment.module	25 Jun 2008 14:31:42 -0000
@@ -1374,24 +1374,14 @@ function comment_form(&$form_state, $edi
     );
   }
 
-  if (!empty($edit['comment'])) {
-    $default = $edit['comment'];
-  }
-  else {
-    $default = '';
-  }
-
-  $form['comment_filter']['comment'] = array(
+  $form['comment'] = array(
     '#type' => 'textarea',
     '#title' => t('Comment'),
     '#rows' => 15,
-    '#default_value' => $default,
+    '#default_value' => !empty($edit['comment']) ? $edit['comment'] : '',
     '#required' => TRUE,
+    '#input_format' => isset($edit['format']) ? $edit['format'] : FILTER_FORMAT_DEFAULT,
   );
-  if (!isset($edit['format'])) {
-    $edit['format'] = FILTER_FORMAT_DEFAULT;
-  }
-  $form['comment_filter']['format'] = filter_form($edit['format']);
 
   $form['cid'] = array(
     '#type' => 'value',
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.213
diff -u -p -r1.213 filter.module
--- modules/filter/filter.module	6 May 2008 12:18:47 -0000	1.213
+++ modules/filter/filter.module	25 Jun 2008 14:31:43 -0000
@@ -466,18 +466,24 @@ function check_markup($text, $format = F
  * @param $weight
  *   The weight of the input format.
  * @param $parents
- *   Required when defining multiple input formats on a single node or having a different parent than 'format'.
+ *   Required when the input format selector is rendered in a tree
+ *   structure (i.e., when we don't want it to appear at the top level
+ *   of $form_state['values']).
+ * @param $name
+ *   The name used to identify the input format selector in structured
+ *   form arrays. Defaults to 'format'.
  * @return
- *   HTML for the form element.
+ *   An associative array containing the structure of the form element.
  */
-function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) {
+function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array(), $name = 'format') {
+  $parents[] = $name;
   $value = filter_resolve_format($value);
   $formats = filter_formats();
 
   $extra = theme('filter_tips_more_info');
 
   if (count($formats) > 1) {
-    $form = array(
+    $form[$name] = array(
       '#type' => 'fieldset',
       '#title' => t('Input format'),
       '#collapsible' => TRUE,
@@ -490,7 +496,7 @@ function filter_form($value = FILTER_FOR
       // Generate the parents as the autogenerator does, so we will have a
       // unique id for each radio button.
       $parents_for_id = array_merge($parents, array($format->format));
-      $form[$format->format] = array(
+      $form[$name][$format->format] = array(
         '#type' => 'radio',
         '#title' => $format->name,
         '#default_value' => $value,
@@ -504,14 +510,14 @@ function filter_form($value = FILTER_FOR
   else {
     // Only one format available: use a hidden form item and only show tips.
     $format = array_shift($formats);
-    $form[$format->format] = array('#type' => 'value', '#value' => $format->format, '#parents' => $parents);
+    $form[$name][$format->format] = array('#type' => 'value', '#value' => $format->format, '#parents' => $parents);
     $tips = _filter_tips(variable_get('filter_default_format', 1), FALSE);
-    $form['format']['guidelines'] = array(
+    $form[$name]['guidelines'] = array(
       '#title' => t('Formatting guidelines'),
       '#value' => theme('filter_tips', $tips, FALSE, $extra),
     );
   }
-  $form[] = array('#value' => $extra);
+  $form[$name][] = array('#value' => $extra);
   return $form;
 }
 
Index: modules/node/node.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.pages.inc,v
retrieving revision 1.30
diff -u -p -r1.30 node.pages.inc
--- modules/node/node.pages.inc	14 Apr 2008 17:48:38 -0000	1.30
+++ modules/node/node.pages.inc	25 Jun 2008 14:31:47 -0000
@@ -289,10 +289,9 @@ function node_body_field(&$node, $label,
     '#default_value' => $include ? $node->body : ($node->teaser . $node->body),
     '#rows' => 20,
     '#required' => ($word_count > 0),
+    '#input_format' => isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT,
   );
 
-  $form['format'] = filter_form($node->format);
-
   return $form;
 }
 
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.603
diff -u -p -r1.603 system.module
--- modules/system/system.module	25 Jun 2008 09:12:25 -0000	1.603
+++ modules/system/system.module	25 Jun 2008 14:31:53 -0000
@@ -229,7 +229,7 @@ function system_elements() {
     '#cols' => 60,
     '#rows' => 5,
     '#resizable' => TRUE,
-    '#process' => array('form_expand_ahah'),
+    '#process' => array('form_expand_ahah', 'form_expand_input_format'),
   );
 
   $type['radios'] = array(
