By askibinski on
According to documentation it should be possible to redirect any form to a custom page of choice using $form['#redirect'].
So I've got someting like this: (in my template.php)
function phptemplate_user_register($form) {
$form['#redirect'] = 'node/124';
$output = drupal_render($form);
return $output;
}
But it just doesn't work. After registration the user is just redirected to the frontpage. I can't find much information on the web about this and according to the drupal pro development book, it should be working...
Comments
I think the redirect to the
I think the redirect to the frontpage finds place somewhere in the user module during the registration process and overrides your redirect.
Is the new user logged in after registration? If so, maybe the module Login Destination ( http://drupal.org/project/login_destination ) offers the functionality you want?
Another solution would be creating a module in which you override hook_user and make use of function drupal_goto.
No the user is not logged in afterwards
No the user is not logged in afterwards, it's registration only.
It seems #redirect has no effect in other forms too - like the personal contact form. There just isn't enough documentation about this - I can't seem to find any working examples...
Albert Skibinski - Homepage
Does the url have a destination?
Does the url have a destination?
Don't know if it's possible to change the url in theming, but adding "destination=node/124" as url parameter should do the trick also.
No it hasn't but...
I don't want to use destination. According to the drupal pro development book (1st edition - page 153, 2nd edition - page 228) it should be possible to do it this way...
Albert Skibinski - Homepage
I think it works OK if
I think it works OK if you're creating custom forms on your own, but in this case the registration process overrides the form redirect.
btw, I saw this thread, maybe it helps -> http://drupal.org/node/202421
You are probably right
Not very consistent behaviour however. You can override most other aspects using $form.
Albert Skibinski - Homepage
Here's the solution
Ok, I got it. It works just fine with #redirect as described above, BUT only when you do implement this using hook_form_alter() in your own module. It doesn't work in template.php (though other overrides work well that way).
Albert Skibinski - Homepage
Glad you found it.
Nothing beats own modules :-)
But what about in the submit function?
I can redirect away from the user-register form by altering the form (mymodule_user_register_alter()) and either setting the desitination or the #redirect property. That works fine.
However, I need to work with the newly created user object before redirecting, so my redirect has to be located in my submit handler. Setting $form_state['redirect'] = 'url'; is supposed to work. But on this form it doesn't.
I've verified that my submit handler is running AFTER the user module's submit handler.
Anyone have any luck redirecting away from the user-register form from within a submit function?
What's the exact code then?
What's the exact code then?
I've got:
In a module and it does not work, what am I missing?
Thanks
replace hook
Replace 'hook' in the function name with your module name.
Albert Skibinski - Homepage
Also
form_alter (like all the alters), doesn't want to do any output. You don't need to render/return your form right there. Just make the change, and let drupal's normal processing handle the rest.
------
Personal: Outlandish Josh
Professional: Chapter Three
------
Personal: Outlandish Josh
Professional: Pantheon
My solution (Drupal 6)
This code works for me in Drupal 6
nice! works like a charm!
nice! works like a charm! ergo - "destination" is sought after in $_POST and not just in $_GET ($_REQUEST, I assume). Good to know!
having issues
Hi, I'm attempting to implement this on a new drupal site I've been working on and haven't been able to get the redirect working right. Here's what I've got so far, I just made a simple module for the specific purpose of redirecting users to a page once they've registered for the site:
registration_redirect.info:
name = Registration Redirect
description = A module for redirecting users on registration success
core = 6.x
registration_redirect.module:
I'm hoping there has been a simple mistake on my page, any help or a nudge in the right direction is much appreciated! Also, the actual destination page will be some page I'll make at a later date, just want to get the functionality there before moving further.
use exact module name..
I think your module name is registration_redirect but you used registrationredirect for hook_form_alter. So make this change, I hope it works.
I used the Login Destination
I used the Login Destination module (http://drupal.org/project/login_destination) which allows you to specify a redirect url based on the path of the login in the administration configuration. I specified /user/register and it worked like a charm. http://www.jesox.com/posts/login-destination-module-preview