diff --git includes/form.inc includes/form.inc index 4eb5681..bd1d988 100644 --- includes/form.inc +++ includes/form.inc @@ -1393,12 +1393,15 @@ function form_type_image_button_value($form, $input, $form_state) { * The form element whose value is being populated. * @param $input * The incoming input to populate the form element. If this is FALSE, - * the element's default value should be returned. + * attempt to get the value from $form_state if it is not NULL. Otherwise + * return nothing, which should result in default value being assigned. + * @param $form_state + * The incoming form state array which may be used to deduce a value. * @return * The data that will appear in the $element_state['values'] collection * for this element. Return nothing to use the default. */ -function form_type_checkbox_value($element, $input = FALSE) { +function form_type_checkbox_value($element, $input = FALSE, $form_state = NULL) { if ($input !== FALSE) { if (empty($element['#disabled'])) { return !empty($input) ? $element['#return_value'] : 0; @@ -1407,6 +1410,10 @@ function form_type_checkbox_value($element, $input = FALSE) { return $element['#default_value']; } } + if ($form_state != NULL && !empty($form_state['values'][$element['#name']])) { + return $form_state['values'][$element['#name']]; + } + } /** @@ -1416,12 +1423,15 @@ function form_type_checkbox_value($element, $input = FALSE) { * The form element whose value is being populated. * @param $input * The incoming input to populate the form element. If this is FALSE, - * the element's default value should be returned. + * attempt to get the value from $form_state if it is not NULL. Otherwise + * return nothing, which should result in default value being assigned. + * @param $form_state + * The incoming form state array which may be used to deduce a value. * @return * The data that will appear in the $element_state['values'] collection * for this element. Return nothing to use the default. */ -function form_type_checkboxes_value($element, $input = FALSE) { +function form_type_checkboxes_value($element, $input = FALSE, $form_state = NULL) { if ($input === FALSE) { $value = array(); $element += array('#default_value' => array()); @@ -1433,6 +1443,9 @@ function form_type_checkboxes_value($element, $input = FALSE) { elseif (!isset($input)) { return array(); } + if ($form_state != NULL && !empty($form_state['values'][$element['#name']])) { + return $form_state['values'][$element['#name']]; + } } /** @@ -1443,16 +1456,23 @@ function form_type_checkboxes_value($element, $input = FALSE) { * The form element whose value is being populated. * @param $input * The incoming input to populate the form element. If this is FALSE, - * the element's default value should be returned. + * attempt to get the value from $form_state if it is not NULL. Otherwise + * return nothing, which should result in default value being assigned. + * @param $form_state + * The incoming form state array which may be used to deduce a value. * @return * The data that will appear in the $element_state['values'] collection * for this element. Return nothing to use the default. */ -function form_type_password_confirm_value($element, $input = FALSE) { +function form_type_password_confirm_value($element, $input = FALSE, $form_state = NULL) { if ($input === FALSE) { $element += array('#default_value' => array()); return $element['#default_value'] + array('pass1' => '', 'pass2' => ''); } + if ($form_state != NULL && !empty($form_state['values'][$element['#name']])) { + return $form_state['values'][$element['#name']]; + } + } /** @@ -1462,12 +1482,15 @@ function form_type_password_confirm_value($element, $input = FALSE) { * The form element whose value is being populated. * @param $input * The incoming input to populate the form element. If this is FALSE, - * the element's default value should be returned. + * attempt to use $form_state, if it is populated. Otherwise, return nothing, + * which should cause the default to be used. + * @param $form_state + * The incoming form state array which may be used to deduce a value. * @return * The data that will appear in the $element_state['values'] collection * for this element. Return nothing to use the default. */ -function form_type_select_value($element, $input = FALSE) { +function form_type_select_value($element, $input = FALSE, $form_state = NULL) { if ($input !== FALSE) { if (isset($element['#multiple']) && $element['#multiple']) { return (is_array($input)) ? drupal_map_assoc($input) : array(); @@ -1476,6 +1499,9 @@ function form_type_select_value($element, $input = FALSE) { return $input; } } + if ($form_state != NULL && !empty($form_state['values'][$element['#name']])) { + return $form_state['values'][$element['#name']]; + } } /** @@ -1485,17 +1511,23 @@ function form_type_select_value($element, $input = FALSE) { * The form element whose value is being populated. * @param $input * The incoming input to populate the form element. If this is FALSE, - * the element's default value should be returned. + * attempt to use $form_state, if it is populated. Otherwise, return nothing, + * which should cause the default to be used. + * @param $form_state + * The incoming form state array which may be used to deduce a value. * @return * The data that will appear in the $element_state['values'] collection * for this element. Return nothing to use the default. */ -function form_type_textfield_value($element, $input = FALSE) { +function form_type_textfield_value($element, $input = FALSE, $form_state = NULL) { if ($input !== FALSE) { // Equate $input to the form value to ensure it's marked for // validation. return str_replace(array("\r", "\n"), '', $input); } + if ($form_state != NULL && !empty($form_state['values'][$element['#name']])) { + return $form_state['values'][$element['#name']]; + } } /** @@ -1505,15 +1537,21 @@ function form_type_textfield_value($element, $input = FALSE) { * The form element whose value is being populated. * @param $input * The incoming input to populate the form element. If this is FALSE, - * the element's default value should be returned. + * attempt to use $form_state, if it is populated. Otherwise, return nothing, + * which should cause the default to be used. + * @param $form_state + * The incoming form state array which may be used to deduce a value. * @return * The data that will appear in the $element_state['values'] collection * for this element. Return nothing to use the default. */ -function form_type_token_value($element, $input = FALSE) { +function form_type_token_value($element, $input = FALSE, $form_state = NULL) { if ($input !== FALSE) { return (string)$input; } + if ($form_state != NULL && !empty($form_state['values'][$element['#name']])) { + return $form_state['values'][$element['#name']]; + } } /**