Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.32
diff -u -r1.32 form.inc
--- includes/form.inc	14 Dec 2005 20:06:41 -0000	1.32
+++ includes/form.inc	14 Dec 2005 23:19:51 -0000
@@ -145,6 +145,15 @@
     if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') {
       form_error($elements, t('%name field is required', array('%name' => $elements['#title'])));
     }
+    
+    // Add legal choice check if element has #options.
+    if (isset($elements['#options'])) {
+      if (!isset($elements['#validate']['form_legal_choice'])) {
+        $elements['#validate']['form_legal_choice_check'] = array();
+      }
+    }
+ 
+    // User-applied checks.
     if (isset($elements['#validate'])) {
       foreach ($elements['#validate'] as $function => $args) {
         $args = array_merge(array($elements), $args);
@@ -153,6 +162,7 @@
           $args = array_merge(array($form_id, $GLOBALS['form_values']), $args);
         }
         if (function_exists($function))  {
+          // if ($function == 'form_legal_choice_check') dprint_r($elements);
           call_user_func_array($function, $args);
         }
       }
@@ -169,6 +179,33 @@
 }
 
 /**
+ * Validator: Legal choice check.
+ *
+ * @param mixed $element
+ *   The element to be checked.
+ * @return none
+ *   Performs a form_set_error() if invalid choice is discovered.
+ */
+function form_legal_choice_check($element, $msg = null) {
+  $value = $element['#value'];
+  $choices = $element['#options'];
+  if (!isset($value) || $value === '') { 
+    return; // allow no choice
+  }
+  if (!is_array($choices)) { // if no choices set an error
+    $msg ? form_error($element, $msg) : form_error($element, t('Illegal choice (none provided).'));  
+  }
+  if (!is_array($value)) {
+    $value = array($value);
+  }
+  foreach ($value as $key => $v) {   
+    if ($key && !array_key_exists($key, $choices)) {
+      $msg ? form_error($element, $msg) : form_error($element, t('Illegal choice in %title: %val.', array('%title' => theme('placeholder', $element['#title']), '%val' => theme('placeholder', $v))));
+    }
+  }
+}
+
+/**
  * File an error against a form element. If the name of the element is
  * edit[foo][bar] then you may pass either foo or foo][bar as $name
  * foo will set an error for all its children.
Index: modules/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter.module,v
retrieving revision 1.95
diff -u -r1.95 filter.module
--- modules/filter.module	14 Dec 2005 20:08:30 -0000	1.95
+++ modules/filter.module	14 Dec 2005 23:19:52 -0000
@@ -775,7 +775,6 @@
         '#return_value' => $format->format,
         '#parents' => $parents,
         '#description' => theme('filter_tips', _filter_tips($format->format, false)),
-        '#validate' => array('filter_form_validate' => array())
       );
     }
   }
@@ -793,18 +792,6 @@
   return $form;
 }
 
-function filter_form_validate($element) {
-  static $validated;
-  if ($validated) {
-    return;
-  }
-  $validated = 1;
-  $formats = filter_formats();
-  if (!isset($formats[$element['#value']])) {
-    form_set_error($element['#parents'][0], t('The supplied input format is invalid.'));
-  }
-}
-
 /**
  * Returns true if the user is allowed to access this format.
  */
