Drupal 8 Form Redirect On Failed Validation I have a form which, upon failed validation, should query a custom/non-Drupal table, and if that query is successful, to redirect the user to a custom page that is only accessible through a logged-in state (so I need to "fake" successful authentication even if the user does not exist in the official Drupal users table).

The query to the custom table essentially checks a secondary user list in non-Drupal format upon failing to authenticate the official way, and if successful, would redirect the user to another page where they could select a Drupal username and password combination in order to register them in the system / make an official account.

This is the relevant code inside my form validation method:

if ($this-&gt;userAuth-&gt;authenticate($form_state-&gt;getValue('name'), $password) == FALSE) {
    // other stuff
    $uid = $this-&gt;userAuth-&gt;authenticate($form_state-&gt;getValue('name'), $password);
    $form_state-&gt;set('uid', $uid);

    $response = new TrustedRedirectResponse('/path/destination');
    $form_state-&gt;setResponse($response);
}


I have also tried this instead of the new TrustedRedirectResponse:

    $redirect_path = "/path/destination";
    $url = url::fromUserInput($redirect_path);
    $form_state-&gt;setRedirectUrl($url);
If you want the redirect to happen immediately, you can do it like this:

use Symfony\Component\HttpFoundation\RedirectResponse;


$response = new RedirectResponse('/path/destination');

$response-&gt;send();