开发者

Drupal: Stay on same page after registration

I have a block with the registration form in it, I need people to register and stay on that same exact page, is that possible?

I tried the login destination module but that feature only seem to 开发者_运维问答work on the login not register. Register keep sending to user profile page.


As you can see in the user_register_submit submit handler, $form_state['submit'] is hardcoded.

That means that user_register_submit will define the destination, unless you override it.

You can do that by adding your own submit handler (pseudo code).

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "user_register") {
    //Look at the code in user_register_submit for all the ifs and switches to only
    // add this extra handler when a normal user signs up.
    $form['#submit'][] = "_mymodule_user_register_submit";
  }
}

function _mymodule_user_register_submit($form, &$form_state) {
  $form_state['redirect'] = $_GET['q']; //Adds the current url as redirect.
}

Then, using the weights in the system table, make sure your modulestarts after the user module. Otherwise they are called alphabetically, user module coming after mymodule; resetting the redirect again.

And never, ever, use drupal_goto() in submit handlers, because they will stop all processing and redirect the user, causing many modules to fail and often even causing broken and inconsistent databases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜