=== modified file 'includes/form.inc'
--- includes/form.inc
+++ includes/form.inc
@@ -512,12 +537,13 @@ 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']) {
     form_set_value($form, $form['#value']);
   }

   // Recurse through all child elements.
   $count  = 0;
   foreach (element_children($form) as $key) {
+    $form[$key]['#parent'] = &$form;
     // don't squash an existing tree value
     if (!isset($form[$key]['#tree'])) {
       $form[$key]['#tree'] = $form['#tree'];
@@ -783,7 +866,7 @@ 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";
+  return '<fieldset' . drupal_attributes($element['#attributes']) .'>' . ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . ($element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . $element['#children'] . "</fieldset>\n";
 }

 /**
@@ -842,7 +925,28 @@ function theme_password_confirm($element
   return theme('form_element', $element, '<div class="container-inline">'. $element['#children'] .'</div>');
 }

-/*
+/**
+ * Find siblings of a given type of an element.
+ *
+ * @param $element
+ *  The element to start from.
+ * @param $type
+ *  The type of siblings we are interested in.
+ * @return
+ *  An array of form elements which are siblings of $element
+ *  and their type is $type.
+ */
+function form_find_siblings($element, $type = 'fieldset') {
+  $siblings = array();
+  foreach (element_children($element['#parent']) as $key) {
+    if ($element['#parent'][$key]['#type'] == $type) {
+      $siblings[] = $element['#parent'][$key];
+    }
+  }
+  return $siblings;
+}
+
+/**
  * Expand a password_confirm field into two text boxes.
  */
 function expand_password_confirm($element) {
=== modified file 'modules/filter/filter.module'
--- modules/filter/filter.module
+++ modules/filter/filter.module
@@ -808,6 +810,7 @@ function filter_form($value = FILTER_FOR
       '#collapsed' => TRUE,
       '#weight' => $weight,
       '#validate' => array('filter_form_validate' => array()),
+      '#after_build' => array('filter_form_after_build'),
     );
     // Multiple formats available: display radio buttons with tips.
     foreach ($formats as $format) {
@@ -838,15 +841,25 @@ function filter_form($value = FILTER_FOR
   return $form;
 }

-function filter_form_validate($form) {
+function filter_form_after_build($form) {
+  unset($form['#value']);
   foreach (element_children($form) as $key) {
     if ($form[$key]['#value'] == $form[$key]['#return_value']) {
-      return;
+      $form['#value'] = &$form[$key]['#value'];
+    }
     }
+  if (!isset($form['#target'])) {
+    $form['#target'] = form_find_siblings($form, 'textarea');
   }
+  return $form;
+}
+
+function filter_form_validate($form) {
+  if (!isset($form['#value'])) {
   form_error($form, t('An illegal choice has been detected. Please contact the site administrator.'));
   watchdog('form', t('Illegal choice %choice in %name element.', array('%choice' => theme('placeholder', check_plain($v)), '%name' => theme('placeholder', empty($form['#title']) ? $form['#parents'][0] : $form['#title']))), WATCHDOG_ERROR);
 }
+}

 /**
  * Returns TRUE if the user is allowed to access this format.
