form_set_value
- Versions
- 4.7 – 5
form_set_value($form, $value)- 6
form_set_value($form_item, $value, &$form_state)- 7
form_set_value($element, $value, &$form_state)
Change submitted form values during the form processing cycle.
Use this function to change the submitted value of a form item in the validation phase so that it persists in $form_state through to the submission handlers in the submission phase.
Since $form_state['values'] can either be a flat array of values, or a tree of nested values, some care must be taken when using this function. Specifically, $element['#parents'] is an array that describes the branch of the tree whose value should be updated. For example, if we wanted to update $form_state['values']['one']['two'] to 'new value', we'd pass in $element['#parents'] = array('one', 'two') and $value = 'new value'.
Parameters
$element The form item that should have its value updated. Keys used: #parents, #value. In most cases you can just pass in the right element from the $form array.
$value The new value for the form item.
$form_state The array where the value change should be recorded.
Related topics
Code
includes/form.inc, line 1575
<?php
function form_set_value($element, $value, &$form_state) {
_form_set_value($form_state['values'], $element, $element['#parents'], $value);
}
?>Login or register to post comments 