Skip to main content
Rollback to Revision 1
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Due to caching, you can't modify the form_state from hook_form_alter() anymore. Instead, in order to set or alter the redirect destination of a form, you need to attach a #submit handler to any action buttons available on the form, e.g.:

$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';

and set the redirect destination in there:

function mymodule_form_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('user.page');
}

For the correct way to redirect in a form see How to redirect to a page after submitting a form

Due to caching, you can't modify the form_state from hook_form_alter() anymore. Instead, in order to set or alter the redirect destination of a form, you need to attach a #submit handler to any action buttons available on the form, e.g.:

$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';

and set the redirect destination in there:

function mymodule_form_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('user.page');
}

For the correct way to redirect in a form see How to redirect to a page after submitting a form

Due to caching, you can't modify the form_state from hook_form_alter() anymore. Instead, in order to set or alter the redirect destination of a form, you need to attach a #submit handler to any action buttons available on the form, e.g.:

$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';

and set the redirect destination in there:

function mymodule_form_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('user.page');
}
added 147 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

Due to caching, you can't modify the form_state from hook_form_alter() anymore. Instead, in order to set or alter the redirect destination of a form, you need to attach a #submit handler to any action buttons available on the form, e.g.:

$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';

and set the redirect destination in there:

function mymodule_form_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('user.page');
}

For the correct way to redirect in a form see How to redirect to a page after submitting a form

Due to caching, you can't modify the form_state from hook_form_alter() anymore. Instead, in order to set or alter the redirect destination of a form, you need to attach a #submit handler to any action buttons available on the form, e.g.:

$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';

and set the redirect destination in there:

function mymodule_form_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('user.page');
}

Due to caching, you can't modify the form_state from hook_form_alter() anymore. Instead, in order to set or alter the redirect destination of a form, you need to attach a #submit handler to any action buttons available on the form, e.g.:

$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';

and set the redirect destination in there:

function mymodule_form_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('user.page');
}

For the correct way to redirect in a form see How to redirect to a page after submitting a form

Source Link

Due to caching, you can't modify the form_state from hook_form_alter() anymore. Instead, in order to set or alter the redirect destination of a form, you need to attach a #submit handler to any action buttons available on the form, e.g.:

$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';

and set the redirect destination in there:

function mymodule_form_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('user.page');
}