8.5.x FormSubmitterInterface.php FormSubmitterInterface::redirectForm(FormStateInterface $form_state)
8.0.x FormSubmitterInterface.php FormSubmitterInterface::redirectForm(FormStateInterface $form_state)
8.1.x FormSubmitterInterface.php FormSubmitterInterface::redirectForm(FormStateInterface $form_state)
8.2.x FormSubmitterInterface.php FormSubmitterInterface::redirectForm(FormStateInterface $form_state)
8.3.x FormSubmitterInterface.php FormSubmitterInterface::redirectForm(FormStateInterface $form_state)
8.4.x FormSubmitterInterface.php FormSubmitterInterface::redirectForm(FormStateInterface $form_state)
8.6.x FormSubmitterInterface.php FormSubmitterInterface::redirectForm(FormStateInterface $form_state)

Redirects the user to a URL after a form has been processed.

After a form is submitted and processed, normally the user should be redirected to a new destination page. This function figures out what that destination should be, based on the $form_state and the 'destination' query string in the request URL, and redirects the user there.

The result of \Drupal\Core\Form|FormStateInterface::getRedirect() determines where to redirect the user. See the possible return values listed there. If the result is FALSE, then the user will not be redirected.

Here is an example of how to set up a form to redirect to the path 'user':

$form_state
  ->setRedirect('user.page');

And here is an example of how to redirect to 'node/123?foo=bar#baz':


$form_state->setRedirect('entity.node.canonical',
  array('node' => 123),
  array(
    'query' => array(
      'foo' => 'bar',
    ),
    'fragment' => 'baz',
  ),
));

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse|null

See also

\Drupal\Core\Form\FormBuilderInterface::processForm()

\Drupal\Core\Form\FormBuilderInterface::buildForm()

2 methods override FormSubmitterInterface::redirectForm()
FormBuilder::redirectForm in core/lib/Drupal/Core/Form/FormBuilder.php
Redirects the user to a URL after a form has been processed.
FormSubmitter::redirectForm in core/lib/Drupal/Core/Form/FormSubmitter.php
Redirects the user to a URL after a form has been processed.

File

core/lib/Drupal/Core/Form/FormSubmitterInterface.php, line 76

Class

FormSubmitterInterface
Provides an interface for processing form submissions.

Namespace

Drupal\Core\Form

Code

public function redirectForm(FormStateInterface $form_state);