Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.265.2.4
diff -u -r1.265.2.4 form.inc
--- includes/form.inc	11 Feb 2008 14:45:57 -0000	1.265.2.4
+++ includes/form.inc	6 Mar 2008 16:01:10 -0000
@@ -972,14 +972,12 @@
       foreach ($form['#parents'] as $parent) {
         $edit = isset($edit[$parent]) ? $edit[$parent] : NULL;
       }
-      if (!$form['#programmed'] || isset($edit)) {
-        // Call #type_value to set the form value;
-        if (function_exists($function)) {
-          $form['#value'] = $function($form, $edit);
-        }
-        if (!isset($form['#value']) && isset($edit)) {
-          $form['#value'] = $edit;
-        }
+      // Call #type_value to set the form value;
+      if (function_exists($function)) {
+        $form['#value'] = $function($form, $edit);
+      }
+      if (!isset($form['#value']) && isset($edit)) {
+        $form['#value'] = $edit;
       }
       // Mark all posted values for validation.
       if (isset($form['#value']) || (isset($form['#required']) && $form['#required'])) {
@@ -1151,15 +1149,24 @@
  *   The form element whose value is being populated.
  * @param $edit
  *   The incoming POST data to populate the form element. If this is FALSE,
- *   the element's default value should be returned.
+ *   the element's default value should be returned. $edit may be NULL, which
+ *   means no input exists.
  * @return
  *   The data that will appear in the $form_state['values'] collection
  *   for this element. Return nothing to use the default.
  */
 function form_type_checkbox_value($form, $edit = FALSE) {
   if ($edit !== FALSE) {
-    return !empty($edit) ? $form['#return_value'] : 0;
-  }
+    $disabled = !empty($form['#disabled']) || !empty($form['#attributes']['disabled']);
+    if ((!isset($edit) && $form['#programmed']) || $disabled) {
+      // We let FAPI pick the default value in two circumstances:
+      // 1. If no input exists and at the same time this is a programmed form.
+      // 2. If the checkbox is disabled.
+    }
+    else {
+      return !empty($edit) ? $form['#return_value'] : 0;
+    }
+  } 
 }
 
 /**
@@ -1169,7 +1176,8 @@
  *   The form element whose value is being populated.
  * @param $edit
  *   The incoming POST data to populate the form element. If this is FALSE,
- *   the element's default value should be returned.
+ *   the element's default value should be returned. $edit may be NULL, which
+ *   means no input exists.
  * @return
  *   The data that will appear in the $form_state['values'] collection
  *   for this element. Return nothing to use the default.
@@ -1183,8 +1191,16 @@
     }
     return $value;
   }
-  elseif (!isset($edit)) {
-    return array();
+  else {
+    $disabled = !empty($form['#disabled']) || !empty($form['#attributes']['disabled']);
+    if ((!isset($edit) && $form['#programmed']) || $disabled) {
+      // We let FAPI pick the default value in two circumstances:
+      // 1. If no input exists and at the same time this is a programmed form.
+      // 2. If the checkboxes are disabled.
+    }
+    elseif (!isset($edit)) {
+      return array();
+    }
   }
 }
 
@@ -1196,7 +1212,8 @@
  *   The form element whose value is being populated.
  * @param $edit
  *   The incoming POST data to populate the form element. If this is FALSE,
- *   the element's default value should be returned.
+ *   the element's default value should be returned. $edit may be NULL, which
+ *   means no input exists.
  * @return
  *   The data that will appear in the $form_state['values'] collection
  *   for this element. Return nothing to use the default.
@@ -1215,18 +1232,24 @@
  *   The form element whose value is being populated.
  * @param $edit
  *   The incoming POST data to populate the form element. If this is FALSE,
- *   the element's default value should be returned.
+ *   the element's default value should be returned. $edit may be NULL, which
+ *   means no input exists.
  * @return
  *   The data that will appear in the $form_state['values'] collection
  *   for this element. Return nothing to use the default.
  */
 function form_type_select_value($form, $edit = FALSE) {
   if ($edit !== FALSE) {
-    if (isset($form['#multiple']) && $form['#multiple']) {
-      return (is_array($edit)) ? drupal_map_assoc($edit) : array();
+    if (!isset($edit)) {
+      // If no input exists, we let FAPI pick the default value.
     }
     else {
-      return $edit;
+      if (isset($form['#multiple']) && $form['#multiple']) {
+        return (is_array($edit)) ? drupal_map_assoc($edit) : array();
+      }
+      else {
+        return $edit;
+      }
     }
   }
 }
@@ -1238,16 +1261,22 @@
  *   The form element whose value is being populated.
  * @param $edit
  *   The incoming POST data to populate the form element. If this is FALSE,
- *   the element's default value should be returned.
+ *   the element's default value should be returned. $edit may be NULL, which
+ *   means no input exists.
  * @return
  *   The data that will appear in the $form_state['values'] collection
  *   for this element. Return nothing to use the default.
  */
 function form_type_textfield_value($form, $edit = FALSE) {
   if ($edit !== FALSE) {
-    // Equate $edit to the form value to ensure it's marked for
-    // validation.
-    return str_replace(array("\r", "\n"), '', $edit);
+    if (!isset($edit)) {
+      // If no input exists, we let FAPI pick the default value.
+    }
+    else {
+      // Equate $edit to the form value to ensure it's marked for
+      // validation.
+      return str_replace(array("\r", "\n"), '', $edit);
+    }
   }
 }
 
@@ -1258,14 +1287,20 @@
  *   The form element whose value is being populated.
  * @param $edit
  *   The incoming POST data to populate the form element. If this is FALSE,
- *   the element's default value should be returned.
+ *   the element's default value should be returned. $edit may be NULL, which
+ *   means no input exists.
  * @return
  *   The data that will appear in the $form_state['values'] collection
  *   for this element. Return nothing to use the default.
  */
 function form_type_token_value($form, $edit = FALSE) {
   if ($edit !== FALSE) {
-    return (string)$edit;
+    if (!isset($edit)) {
+      // If no input exists, we let FAPI pick the default value.
+    }
+    else {
+      return (string)$edit;
+    }
   }
 }
 
