0

I'd like users registering on my website are redirected to the page where they clicked the "create account" button which is in a modal.

First, I tried to redirect to an absolute url I tried

$form_state->setRedirect($myUrl);

I tried

$_REQUEST['destination'] = '<front>';

I tried this too :

$response = new \Drupal\Core\Routing\TrustedRedirectResponse('http://www.google.be');
$form_state->setResponse($response);

I'm always redirected to /user/[uid]/edit

5
  • You could use Rules module to achieve that..
    – dharma
    Jun 15, 2017 at 12:05
  • Does Rules module allow to go to the previous page ?
    – lbogdan
    Jun 15, 2017 at 12:59
  • A page redirect can be done to "a drupal path, path alias or external URL"
    – dharma
    Jun 15, 2017 at 13:25
  • @dharma true for D7, but I would really, really, repeat really, want to see an improved version of your answer that explains HOW to do this with Rules in D8 ... Jun 15, 2017 at 14:51
  • For Drupal 8,9,10. you can use module Redirect After Registration
    – Bob Wasan
    May 14 at 5:22

1 Answer 1

0

You can accomplish this with the Rules Link module, and using the PHP variable %server[HTTP_REFERER] or, without having to enable PHP in rules, you can use a custom previous page token, as explained in Provide a token for [current-page:referrer].

Create a rule that triggers when the link is clicked, stores the previous page in a variable, does some other actions you want, and (at the end) redirects to that previous page variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.