unset form error for specific field I have a a kind of conditional field for a sign up form where the user can optionally sign up with a mobile number or an email address.

I'm trying out a custom form validate eg.

  function signup_validate($form, FormStateInterface $form_state) {
    $mobile = $form_state-&gt;getValue('field_mobile');
    $email = $form_state-&gt;getValue('field_email_address');

    if ($email[0]['value'] != '' || $mobile[0]['value'] != '') {
      $form_state-&gt;clearErrors();
    }
  }


Now clearErrors();  obviously clears all errors for the form even if other fields are invalid, I want to know how to clear the error only for field_mobile or field_email_address
While I agree with the accepted answer, one way to accomplish your goal is to:


Assign the form errors to a variable, such as $form_errors
Clear all form errors from $form_state
Remove the particular form error from $form_errors
Loop through the remaining $form_errors, re-setting them to $form_state.


So to clear the field_mobile error you would use the following code:

// Temporarily store all form errors.
$form_errors = $form_state-&gt;getErrors();

// Clear the form errors.
$form_state-&gt;clearErrors();

// Remove the field_mobile form error.
unset($form_errors['field_mobile']);

// Now loop through and re-apply the remaining form error messages.
foreach ($form_errors as $name =&gt; $error_message) {
  $form_state-&gt;setErrorByName($name, $error_message);
}