user2618050
user2618050

Reputation: 51

How to redirect user after registration on Drupal 8?

How to redirect user to a particular page after the user is successfully registered into the site?

Here drupal_goto() does not work. We need to work with the form redirection. How can this be achieved?

Upvotes: 2

Views: 4035

Answers (2)

user2618050
user2618050

Reputation: 51

// include the Url namespace in your custom module
use Drupal\Core\Url;

// Add CUSTOM SUBMIT HANDLER FOR REGISTRATION
$form['actions']['submit']['#submit'][] = '__tmp_registration_submit';

function __tmp_registration_submit(&$form, FormStateInterface $form_state) {
  // set relative internal path
  $redirect_path = "\user\uid\payment-history";
  $url = url::fromUserInput($redirect_path);
  // set redirect
  $form_state->setRedirectUrl($url);
}

Upvotes: 2

user2486435
user2486435

Reputation:

Maybe a bit heavy, but you could also use the Rules module.

Upvotes: 0

Related Questions