Community & Support

Redirect user to specific page after registration

Hello there,
I am trying to redirect user to specific page after registration. I did use LoginToBoggan but it was messing up with the core login system so I want to write code which will redirect user to specific page, that's it.

I am using below code to give redirection and it is working. It takes me to the desired page

<?php
function miscellaneous_form_alter($form, &$form_state, $form_id){
    switch(
$form_id){
        case
'user_register':
           
$key = array_search('user_register_submit', $form['#submit']);
            if (
$key !== FALSE) {
                unset(
$form['#submit'][$key]);
            }
           
array_unshift($form['#submit'],'miscellaneous_user_register_submit');
        break;
    }
}

function
miscellaneous_user_register_submit($form, &$form_state) {
   
drupal_set_message(t("Miscellaneous module is invoked"));
   
$form_state['redirect'] = 'thank-you-for-registering';
}
?>

It redirects the user to the desired page but as I have unset main "user_register_submit" it doesn't create a new user :D

So how can I create the user from miscellaneous module?

Or is there any other way to accomplish this? (I don't want to edit user.module file)

Comments

_

Maybe see how login_destination does it?

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Rules helped

Hello WoldFallz,
Thanks for giving insight. I went through the code of login_destination but it was pretty different then what I wanted so it didn't help.

Though I searched more into forums and had an idea to use Rules module. I installed the module, created a rule which provides "Page Redirect" when "user is created" and it's working fine.

The main issue with my website was crashing of login system while using LoginToboggan is also overcome. Now login system is working fine after installing and applying Rules.

Thanks again.

Rules worked perfectly

Change X (rules_X) in the exported code in the number you like.

<?php
array (
 
'rules' =>
  array (
   
'rules_X' =>
    array (
     
'#type' => 'rule',
     
'#set' => 'event_user_insert',
     
'#label' => 'Register redirect',
     
'#active' => 1,
     
'#weight' => '0',
     
'#categories' =>
      array (
       
0 => 'user',
      ),
     
'#status' => 'custom',
     
'#conditions' =>
      array (
      ),
     
'#actions' =>
      array (
       
0 =>
        array (
         
'#weight' => 0,
         
'#info' =>
          array (
           
'label' => 'Page redirect',
           
'module' => 'System',
           
'eval input' =>
            array (
             
0 => 'path',
             
1 => 'query',
             
2 => 'fragment',
            ),
          ),
         
'#name' => 'rules_action_drupal_goto',
         
'#settings' =>
          array (
           
'path' => 'user/login',
           
'query' => '',
           
'fragment' => '',
           
'force' => 0,
           
'immediate' => 0,
          ),
         
'#type' => 'action',
        ),
      ),
     
'#version' => 6003,
    ),
  ),
)
?>

function modulename_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_register') {
// add two additional submit handlers
$form['#submit'][] = 'modulename_user_register_beforesubmit';
$form['#submit'] = array_reverse($form['#submit']);
$form['#submit'][] = 'modulename_user_register_aftersubmit';
}
}

function modulename_user_register_beforesubmit ($form, &$form_state) {
//code to execute before user register submit function
}

function modulename_user_register_aftersubmit ($form, &$form_state) {
//code to execute after user register submit function
}

Actually LoginToBoggan works perfectly for this purpose. No need to go 4 Rules

nobody click here