function FormStateInterface::setValueForElement
Same name in other branches
- 9 core/lib/Drupal/Core/Form/FormStateInterface.php \Drupal\Core\Form\FormStateInterface::setValueForElement()
- 8.9.x core/lib/Drupal/Core/Form/FormStateInterface.php \Drupal\Core\Form\FormStateInterface::setValueForElement()
- 11.x core/lib/Drupal/Core/Form/FormStateInterface.php \Drupal\Core\Form\FormStateInterface::setValueForElement()
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
array $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->getValue(['elem1', 'elem2']), you would set $element['#parents'] = ['elem1','elem2'].
mixed $value: The new value for the form element.
Return value
$this
1 method overrides FormStateInterface::setValueForElement()
- FormStateDecoratorBase::setValueForElement in core/
lib/ Drupal/ Core/ Form/ FormStateDecoratorBase.php - Changes submitted form values during form validation.
File
-
core/
lib/ Drupal/ Core/ Form/ FormStateInterface.php, line 443
Class
- FormStateInterface
- Provides an interface for an object containing the current state of a form.
Namespace
Drupal\Core\FormCode
public function setValueForElement(array $element, $value);
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.