How to clear form element values after validation error I have a rather complex form validation depending on multiple fields. If validation fails, I would like to set the form values (of all or some explicit fields) to an empty value. This is what I tried, but none of the three approaches works:

public function validateForm(array &amp;$form, FormStateInterface $form_state) {
  ...
  if (!$authorized) {

    $this-&gt;messenger-&gt;addError($this-&gt;t('An error occured.'));

    $form['name']['#value']=''; // approach 1

    $form_state-&gt;setValue('name',''); // approach 2

    $form_state-&gt;setValueForElement($form['name'], ''); // approach 3

    $form_state-&gt;setRebuild();
   }
 }
Have you looked at unsetValue()?

Example usage:

public function validateForm(array &amp;$form, FormStateInterface $form_state) {
  ...
  if (!$authorized) {

    $this-&gt;messenger-&gt;addError($this-&gt;t('An error occurred.'));

    $form_state-&gt;unsetValue('name');

   }
 }


From the doc:


  Removes a specific key from the submitted form values.
  
  
  @param string|array $key
  Values are stored as a multi-dimensional associative array. If $key is a string, it will use unset($values[$key]). If $key is an array, each element of the array will be used as a nested key. If $key = array('foo', 'bar') it will use unset($values['foo']['bar']).