diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-07-14 15:23:29 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-07-14 15:23:29 +0000 |
commit | 834eab503f9b877cbee0cc94d4b951dc5ac2844e (patch) | |
tree | f55545fc5ea7419b405a94ac0c18d3b5b8393be2 /includes | |
parent | 83654b3dd9e160d7ab2a63cc35827d952c213e0d (diff) | |
download | brdo-834eab503f9b877cbee0cc94d4b951dc5ac2844e.tar.gz brdo-834eab503f9b877cbee0cc94d4b951dc5ac2844e.tar.bz2 |
- Patch #121620 by Eaton et al: fixes for formAPI #type .'_value' callback patch.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/form.inc | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/includes/form.inc b/includes/form.inc index 1eff0e66a..92d4fe401 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -797,7 +797,7 @@ function _form_builder_handle_input_element($form_id, &$form, &$form_state) { } if (!isset($form['#value']) && !array_key_exists('#value', $form)) { - $function = 'form_type_'. $form['#type'] . '_value'; + $function = !empty($form['#value_callback']) ? $form['#value_callback'] : '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) { @@ -881,14 +881,16 @@ function _form_builder_handle_input_element($form_id, &$form, &$form_state) { * Helper function to determine the value for a checkbox form element. * * @param $form - * Form element we are trying to determine a value for. + * The form element whose value is being populated. * @param $edit - * Relevant post data for real value, or NULL for default value + * The incoming POST data to populate the form element. If this is FALSE, + * the element's default value should be returned. * @return - * Mixed, value to be assigned to element. + * 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 = NULL) { - if (isset($edit)) { +function form_type_checkbox_value($form, $edit = FALSE) { + if ($edit !== FALSE) { return !empty($edit) ? $form['#return_value'] : 0; } } @@ -897,14 +899,16 @@ function form_type_checkbox_value($form, $edit = NULL) { * Helper function to determine the value for a checkboxes form element. * * @param $form - * Form element we are trying to determine a value for. + * The form element whose value is being populated. * @param $edit - * Relevant post data for real value, or NULL for default value + * The incoming POST data to populate the form element. If this is FALSE, + * the element's default value should be returned. * @return - * Mixed, value to be assigned to element. + * The data that will appear in the $form_state['values'] collection + * for this element. Return nothing to use the default. */ - function form_type_checkboxes_value($form, $edit = NULL) { - if (!isset($edit)) { + function form_type_checkboxes_value($form, $edit = FALSE) { + if ($edit === FALSE) { $value = array(); $form += array('#default_value' => array()); foreach ($form['#default_value'] as $key) { @@ -919,14 +923,16 @@ function form_type_checkbox_value($form, $edit = NULL) { * element. * * @param $form - * Form element we are trying to determine a value for. + * The form element whose value is being populated. * @param $edit - * Relevant post data for real value, or NULL for default value + * The incoming POST data to populate the form element. If this is FALSE, + * the element's default value should be returned. * @return - * Mixed, value to be assigned to element. + * The data that will appear in the $form_state['values'] collection + * for this element. Return nothing to use the default. */ -function form_type_password_confirm_value($form, $edit = NULL) { - if (!isset($edit)) { +function form_type_password_confirm_value($form, $edit = FALSE) { + if ($edit === FALSE) { $form += array('#default_value' => array()); return $form['#default_value'] + array('pass1' => '', 'pass2' => ''); } @@ -936,14 +942,16 @@ function form_type_password_confirm_value($form, $edit = NULL) { * Helper function to determine the value for a select form element. * * @param $form - * Form element we are trying to determine a value for. + * The form element whose value is being populated. * @param $edit - * Relevant post data for real value, or NULL for default value + * The incoming POST data to populate the form element. If this is FALSE, + * the element's default value should be returned. * @return - * Mixed, value to be assigned to element. + * 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 = NULL) { - if (isset($edit)) { +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(); } @@ -957,14 +965,16 @@ function form_type_select_value($form, $edit = NULL) { * Helper function to determine the value for a textfield form element. * * @param $form - * Form element we are trying to determine a value for. + * The form element whose value is being populated. * @param $edit - * Relevant post data for real value, or NULL for default value + * The incoming POST data to populate the form element. If this is FALSE, + * the element's default value should be returned. * @return - * Mixed, value to be assigned to element. + * 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 = NULL) { - if (isset($edit)) { +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); @@ -975,14 +985,16 @@ function form_type_textfield_value($form, $edit = NULL) { * Helper function to determine the value for form's token value. * * @param $form - * Form element we are trying to determine a value for. + * The form element whose value is being populated. * @param $edit - * Relevant post data for real value, or NULL for default value + * The incoming POST data to populate the form element. If this is FALSE, + * the element's default value should be returned. * @return - * Mixed, value to be assigned to element. + * 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 = NULL) { - if (isset($edit)) { +function form_type_token_value($form, $edit = FALSE) { + if ($edit !== FALSE) { return (string)$edit; } } |