? .cache ? .project ? .projectOptions ? files ? includes/form.inc_121620.patch.txt ? modules/upload/upload.install ? sites/all/modules ? sites/default/settings.php Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.195 diff -u -r1.195 form.inc --- includes/form.inc 14 May 2007 13:43:32 -0000 1.195 +++ includes/form.inc 14 May 2007 15:19:22 -0000 @@ -780,66 +780,40 @@ $form['#id'] = form_clean_id('edit-'. implode('-', $form['#parents'])); } + unset($edit); if (!empty($form['#disabled'])) { $form['#attributes']['disabled'] = 'disabled'; } if (!isset($form['#value']) && !array_key_exists('#value', $form)) { + $function = 'form_type_'. $form['#type'] . '_value'; if (($form['#programmed']) || ((!isset($form['#access']) || $form['#access']) && isset($form['#post']) && (isset($form['#post']['form_id']) && $form['#post']['form_id'] == $form_id))) { $edit = $form['#post']; foreach ($form['#parents'] as $parent) { $edit = isset($edit[$parent]) ? $edit[$parent] : NULL; } if (!$form['#programmed'] || isset($edit)) { - switch ($form['#type']) { - case 'checkbox': - $form['#value'] = !empty($edit) ? $form['#return_value'] : 0; - break; - - case 'select': - if (isset($form['#multiple']) && $form['#multiple']) { - if (isset($edit) && is_array($edit)) { - $form['#value'] = drupal_map_assoc($edit); - } - else { - $form['#value'] = array(); - } - } - elseif (isset($edit)) { - $form['#value'] = $edit; - } - break; - - case 'textfield': - if (isset($edit)) { - // Equate $edit to the form value to ensure it's marked for - // validation. - $edit = str_replace(array("\r", "\n"), '', $edit); - $form['#value'] = $edit; - } - break; - - case 'token': - $form['#value'] = (string)$edit; - break; - - default: - if (isset($edit)) { - $form['#value'] = $edit; - } + // Call #type_value to set the form value; + if (function_exists($function)) { + $form['#value'] = $function($form, $edit); } - // Mark all posted values for validation. - if ((isset($form['#value']) && $form['#value'] === $edit) || (isset($form['#required']) && $form['#required'])) { - $form['#needs_validation'] = TRUE; + if (!isset($form['#value']) && isset($edit)) { + $form['#value'] = $edit; } } + // Mark all posted values for validation. + if (isset($form['#value']) || (isset($form['#required']) && $form['#required'])) { + $form['#needs_validation'] = TRUE; + } } + // Load defaults. if (!isset($form['#value'])) { - $function = 'form_'. $form['#type'] .'_value'; + // Call #type_value without a second argument to request default_value handling. if (function_exists($function)) { - $function($form); + $form['#value'] = $function($form); } - else { + // Final catch. If we haven't set a value yet, use the explicit default value. + if(!isset($form['#value'])) { $form['#value'] = isset($form['#default_value']) ? $form['#default_value'] : ''; } } @@ -911,6 +885,70 @@ } /** + * New FormAPI element callback, $form['#type'] .'_value' + * @param $form, form element we are trying to determine a value for. + * @param $edit, relevant post data for real value, or FALSE for default value + * @return mixed, value to be assigned to element. + */ + +/** + * Helper function to load value from default value for checkboxes. + */ +function form_type_checkboxes_value($form, $edit = FALSE) { + if ($edit === FALSE) { + $value = array(); + $form += array('#default_value' => array()); + foreach ($form['#default_value'] as $key) { + $value[$key] = 1; + } + return $value; + } +} + +function form_type_password_confirm_value($form, $edit = FALSE) { + if ($edit === FALSE) { + $form += array('#default_value' => array()); + return $form['#default_value'] + array('pass1' => '', 'pass2' => ''); + } +} + +function form_type_checkbox_value($form, $edit = FALSE) { + if ($edit !== FALSE) { + return !empty($edit) ? $form['#return_value'] : 0; + } +} + +function form_type_select_value($form, $edit = FALSE) { + if ($edit !== FALSE) { + if (isset($form['#multiple']) && $form['#multiple']) { + if (isset($edit) && is_array($edit)) { + return drupal_map_assoc($edit); + } + else { + return array(); + } + } + elseif (isset($edit)) { + return $edit; + } + } +} + +function form_type_textfield_value($form, $edit = FALSE) { + if (isset($edit) && $edit !== FALSE) { + // Equate $edit to the form value to ensure it's marked for + // validation. + return str_replace(array("\r", "\n"), '', $edit); + } +} + +function form_type_token_value($form, $edit = FALSE) { + if ($edit !== FALSE && !empty($edit)) { + return (string)$edit; + } +} + +/** * Use this function to make changes to form values in the form validate * phase, so they will be available in the submit phase in $form_state. * @@ -1316,23 +1354,6 @@ } /** - * Helper function to load value from default value for checkboxes. - */ -function form_checkboxes_value(&$form) { - $value = array(); - $form += array('#default_value' => array()); - foreach ($form['#default_value'] as $key) { - $value[$key] = 1; - } - $form['#value'] = $value; -} - -function password_confirm_value(&$form) { - $form += array('#default_value' => array()); - $form['#value'] = $form['#default_value'] + array('pass1' => '', 'pass2' => ''); -} - -/** * If no default value is set for weight select boxes, use 0. */ function weight_value(&$form) {