0

I am trying to redirect new users after registration depending on values saved in $_SESSION. I use ajax for registration form submission and hook_user_insert fro redirect

function MYMODULE_user_insert(&$edit, $account, $category){
global $user;
if(isset($_SESSION['VAR']) && !$user->uid){
    drupal_goto('path/to/somewhere');

}

Once form is submitted I receive alert AJAX HTTP request terminated abnormally and page html code. What should I change to make redirect working?

  • The redirect code looks good imo. Is a user created? If not, I suspect the ajax you used to manipulate submission threw an error and the redirect wasn't even executed. – Zuzuesque Sep 8 '15 at 14:25
  • Yes. I see user but he has no role (I use autoassignrole module) and never accessed – burzakovskiy Sep 8 '15 at 14:29
1

You should alter the register form and set new redirect value.

function MYMODULE_user_register_form($form, &$form_state) {
  $form_state['redirect'] = 'path/to/somewhere';
}
0

Return

<script type="text/javascript">
  window.location.href="your_location";
</script>

from your ajax callback. Hope you get the idea

0

In case of ajax drupal_goto doesn't work. I found solution here. But it requires custom form submit function.

function MYMODULE_form_user_register_form_alter(&$form, &$form_state) {
$form['#submit'][0] = 'MYMODULE_user_register_form_submit';

}

And to make things work copied code of legacy function from user module

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.