form_set_value

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 form_set_value($form, $value)
6 form_set_value($form_item, $value, &$form_state)
8 – 7 form_set_value($element, $value, &$form_state)

Change submitted form values during form validation.

Use this function to change the submitted value of a form element in a form validation function, so that the changed value persists in $form_state through to the submission handlers.

Note that form validation functions are specified in the '#validate' component of the form array (the value of $form['#validate'] is an array of validation function names). If the form does not originate in your module, you can implement hook_form_FORM_ID_alter() to add a validation function to $form['#validate'].

Parameters

$element The form element that should have its value updated; in most cases you can just pass in the element from the $form array, although the only component that is actually used is '#parents'. If constructing yourself, set $element['#parents'] to be an array giving the path through the form array's keys to the element whose value you want to update. For instance, if you want to update the value of $form['elem1']['elem2'], which should be stored in $form_state['values']['elem1']['elem2'], you would set $element['#parents'] = array('elem1','elem2').

$value The new value for the form element.

$form_state Form state array where the value change should be recorded.

Related topics

▾ 26 functions call form_set_value()

field_example_3text_validate in examples/field_example/field_example.module
Validate the individual fields and then convert them into a single HTML RGB value as text.
field_test_widget_multiple_validate in modules/field/tests/field_test.field.inc
Form element validation handler for 'test_field_widget_multiple' widget.
file_managed_file_submit in modules/file/file.module
Submit handler for upload and remove buttons of managed_file elements.
file_managed_file_validate in modules/file/file.module
An #element_validate callback for the managed_file element.
filter_admin_format_form_validate in modules/filter/filter.admin.inc
Validate text format form submissions.
form_example_phonenumber_combined_validate in examples/form_example/form_example_elements.inc
Phone number validation function for the combined phonenumber.
form_test_element_validate_name in modules/simpletest/tests/form_test.module
Form element validation handler for 'name' in form_test_validate_form().
form_test_validate_form_validate in modules/simpletest/tests/form_test.module
Form validation handler for form_test_validate_form().
list_allowed_values_setting_validate in modules/field/modules/list/list.module
Element validate callback; check that the entered values are valid.
node_search_validate in modules/node/node.module
Form API callback for the search form. Registered in node_form_alter().
number_field_widget_validate in modules/field/modules/number/number.module
FAPI validation of an individual number element.
options_field_widget_validate in modules/field/modules/options/options.module
Form element validation handler for options element.
password_confirm_validate in includes/form.inc
Validate password_confirm element.
path_form_element_validate in modules/path/path.module
Form element validation handler for URL alias form element.
search_form_validate in modules/search/search.pages.inc
As the search form collates keys from other modules hooked in via hook_form_alter, the validation takes place in _submit. search_form_validate() is used solely to set the 'processed_keys' form value for the basic search form.
system_site_information_settings_validate in modules/system/system.admin.inc
Validates the submitted site-information form.
taxonomy_autocomplete_validate in modules/taxonomy/taxonomy.module
Form element validate handler for taxonomy term autocomplete element.
user_account_form_validate in modules/user/user.module
Form validation handler for user_account_form().
user_form_field_ui_field_edit_form_submit in modules/user/user.module
Additional submit handler for the 'Edit field instance' form.
user_pass_validate in modules/user/user.pages.inc
_field_ui_field_overview_form_validate_add_new in modules/field_ui/field_ui.admin.inc
Helper function for field_ui_field_overview_form_validate.
_file_generic_settings_extensions in modules/file/file.field.inc
Element validate callback for the allowed file extensions field.
_file_generic_settings_file_directory_validate in modules/file/file.field.inc
Element validate callback for the file destination field.
_form_builder_handle_input_element in includes/form.inc
Populate the #value and #name properties of input elements so they can be processed and rendered.
_form_validate in includes/form.inc
Performs validation on form elements. First ensures required fields are completed, #maxlength is not exceeded, and selected options were in the list of options given to the user. Then calls user-defined validators.
_image_field_resolution_validate in modules/image/image.field.inc
Element validate function for resolution fields.

Code

includes/form.inc, line 2433

<?php
function form_set_value($element, $value, &$form_state) {
  drupal_array_set_nested_value($form_state['values'], $element['#parents'], $value, TRUE);
}
?>