Index: form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.22
diff -u -r1.22 form.inc
--- form.inc	28 Nov 2005 16:37:11 -0000	1.22
+++ form.inc	1 Dec 2005 20:16:05 -0000
@@ -41,7 +41,8 @@
  * Processes a form array, and produces the HTML output of a form.
  * If there is input in the $_POST['edit'] variable, this function
  * will attempt to validate it, using <code>drupal_validate_form</code>,
- * and then execute the form using <code>drupal_execute_form</code>.
+ * filter it, using <code>drupal_filter_form</code>, and then execute the
+ * form using <code>drupal_execute_form</code>.
  *
  * @param $form_id
  *   A unique string identifying the form. Allows each form to be themed.
@@ -98,6 +99,7 @@
   if (!empty($_POST['edit']) && (($_POST['edit']['form_id'] == $form_id) || ($_POST['edit']['form_id'] == $callback))) {
     drupal_validate_form($form_id, $form, $callback);
     if ($form_submitted && !form_get_errors()) {
+      drupal_filter_form($form_id, $form, $callback);
       drupal_execute_form($form_id, $form, $callback);
     }
   }
@@ -136,6 +138,46 @@
   }
 }
 
+/**
+ * Filter a form's values.
+ *
+ * @param string $form_id
+ * @param array &$form
+ * @param string $callback
+ */
+function drupal_filter_form($form_id, &$form, $callback = NULL) {
+  _form_filter($form);
+}
+
+/**
+ * Filter value of a form element and each of it's children.
+ * For each element that is filtered, the #value property is modified and the
+ * #filtered property is set to true.
+ *
+ * @param &$elements
+ */
+function _form_filter(&$elements) {
+
+  // Recurse through all children.
+  foreach (element_children($elements) as $key) {
+    if (isset($elements[$key]) && $elements[$key]) {
+      _form_filter($elements[$key]);
+    }
+  }
+
+  // Filter the current input.
+  if (!$elements['#filtered'] && $elements['#input']) {
+    if (isset($elements['#filter'])) {
+      foreach ($elements['#filter'] as $func => $args) {
+        $args = array_merge(array($elements['#value']), $args);
+        $elements['#value'] = call_user_func_array($func, $args);
+      }
+    }
+  }
+
+  $elements['#filtered'] = TRUE;
+}
+
 function drupal_execute_form($form_id, $form, $callback = NULL) {
   global $form_values;
 
