? .DS_Store
? f.patch
? format.patch
? includes/.DS_Store
? modules/.DS_Store
? modules/filter/.DS_Store
? sites/formapi
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.181
diff -u -p -r1.181 form.inc
--- includes/form.inc	7 Mar 2007 17:31:40 -0000	1.181
+++ includes/form.inc	13 Mar 2007 14:19:52 -0000
@@ -795,6 +795,7 @@ function form_builder($form_id, $form) {
   foreach (element_children($form) as $key) {
     $form[$key]['#post'] = $form['#post'];
     $form[$key]['#programmed'] = $form['#programmed'];
+    $form[$key]['#parent'] = &$form;
     // Don't squash an existing tree value.
     if (!isset($form[$key]['#tree'])) {
       $form[$key]['#tree'] = $form['#tree'];
@@ -1055,7 +1056,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'] : '') . $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";
 }
 
 /**
@@ -1119,7 +1120,28 @@ function theme_password_confirm($element
   return theme('form_element', $element, $element['#children']);
 }
 
-/*
+/**
+ * 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) {
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.166
diff -u -p -r1.166 filter.module
--- modules/filter/filter.module	12 Mar 2007 11:31:02 -0000	1.166
+++ modules/filter/filter.module	13 Mar 2007 14:19:54 -0000
@@ -793,6 +793,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) {
@@ -820,14 +821,24 @@ 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'];
     }
   }
-  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' => $form[$key]['#value'], '%name' => empty($form['#title']) ? $form['#parents'][0] : $form['#title'])), WATCHDOG_ERROR);
+  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' => $form[$key]['#value'], '%name' => empty($form['#title']) ? $form['#parents'][0] : $form['#title'])), WATCHDOG_ERROR);
+  }
 }
 
 /**
