8.5.x FormState.php FormState::setRedirectUrl(Url $url)
8.0.x FormState.php FormState::setRedirectUrl(Url $url)
8.1.x FormState.php FormState::setRedirectUrl(Url $url)
8.2.x FormState.php FormState::setRedirectUrl(Url $url)
8.3.x FormState.php FormState::setRedirectUrl(Url $url)
8.4.x FormState.php FormState::setRedirectUrl(Url $url)
8.6.x FormState.php FormState::setRedirectUrl(Url $url)

Sets the redirect URL for the form.

Parameters

\Drupal\Core\Url $url: The URL to redirect to.

Return value

$this

Overrides FormStateInterface::setRedirectUrl

See also

\Drupal\Core\Form\FormSubmitterInterface::redirectForm()

1 call to FormState::setRedirectUrl()
FormState::setRedirect in core/lib/Drupal/Core/Form/FormState.php
Sets the redirect for the form.

File

core/lib/Drupal/Core/Form/FormState.php, line 1009

Class

FormState
Stores information about the state of a form.

Namespace

Drupal\Core\Form

Code

public function setRedirectUrl(Url $url) {
  $this->redirect = $url;
  return $this;
}

Comments

joos’s picture

I have a form that after submission should redirect to an external payment gateway. How is that done when you cant send an external URL here?

NickWilde’s picture

Here's an example of the usage:

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\TrustedRedirectResponse;

/**
 * Implements hook_form_alter().
 */
function HOOK_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $response = new TrustedRedirectResponse('https://example.com');
  $form_state->setResponse($response);
}