function form_set_value

Changes 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

27 calls to form_set_value()
Callbacks::validateName in drupal/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Callbacks.php
Form element validation handler for 'name' in form_test_validate_form().
FieldOverview::validateAddNew in drupal/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
Validates the 'add new field' row.
field_test_widget_multiple_validate in drupal/core/modules/field/tests/modules/field_test/field_test.field.inc
Form element validation handler for 'test_field_widget_multiple' widget.
file_managed_file_submit in drupal/core/modules/file/file.module
Form submission handler for upload / remove buttons of managed_file elements.
file_managed_file_validate in drupal/core/modules/file/file.module
Render API callback: Validates the managed_file element.

... See full list

File

drupal/core/includes/form.inc, line 2552
Functions for form and batch generation and processing.

Code

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