0

I am having difficulty getting drupal to redirect a user to a specific page after completing the registration form.

In the user.module file there is this:

// No e-mail verification required; log in user immediately.
elseif (!$admin && !variable_get('user_email_verification', TRUE) && $account->status) {
    _user_mail_notify('register_no_approval_required', $account);
    $form_state['uid'] = $account->uid;
    user_login_submit(array(), $form_state);
    drupal_set_message(t('Registration successful. You are now logged in.'));
    $form_state['redirect'] = '';
}

I would have assumed that by entering the path you wish to redirect to, in the form redirect ,it would redirect. For example:

$form_state['redirect'] = '/page/I/Want/To/Redirect/To';

However this is not the case. When the user is logged in after completing the registration form they are taken to the homepage.

Once the user is logged in (from the registration form) I wish to send them to our services page. But for them to be sent to the homepage every subsequent time they login.

2

There is a very simple way to that using the Rules module.

0

You shouldn't modify core files like that. It doesn't break anything, but it's not considered good practice.

Instead you can implement hook_form_alter and modify the #redirect of the form, or add your own submit handler (#submit) to the user_register_form, then in that submit handler you can modify the $form_state['redirect'].

  • Thanks for the suggestion and I do agree that editing core files is very bad practice. However will your suggestion not give me the same result? If editing the core file $form_state['redirect'] does not work? – dooffas Mar 30 '12 at 10:06
  • It should in theory work, but I haven't tried to implement anything like this. If it doesn't work, as Citricguy suggested you can use the Rules module. See this page: drupal.org/node/134000 there's a section called "How to override default form redirection in Drupal" which has a sample module code and explanation of what overrides what. Also please note, I mistaken #redirect for #action in my original answer. I've corrected the mistake. – Beebee Mar 30 '12 at 10:19
  • @doofas 'Thou shall not touch the Drupal core', is one of the 10 commandements of Drupal way-to-go. Do not lead yourself into this unholly temptation. – drupal_stuff_alter Apr 2 '12 at 6:51
-1

You can use multiple modules Rules, Login Destination and LoginToboggan.

Check Reference link from Drupal Document for more help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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