Posted by calas on March 21, 2007 at 6:10pm
I spent the day figuring out how to redirect to a custom view after a user is created. I do not allow user registration so admins should create them using admin > user > user > create (or an url alias).
Setting $form['#redirect'] in hook_form_alter doesn't work (can anybody tell me why?) so the solution was:
<?php
function mymodule_form_alter($form_id, &$form){
if($form_id == 'user_register'){
$form['destination']['#value'] = 'custom/view/path';
}
}
?>It works like charm for me, hope it helps someone.
Comments
I have been trying to work
I have been trying to work out how to redirect someone upon registration too. I tried the 'insert' $op of hook_user but doing a drupal_goto() there seems to break the registration process - the account is created, but the email isn't sent.
When I tried your trick, however, I found that all it did was alter the registration form to include the value (custom/view/path in your example) as a bare string down the bottom of the form, in between a couple of hidden inputs.
Any ideas on why this may be happening? I'm using the Profile module if that makes a difference.
EDIT:
$form['#redirect'] worked for me. So there we go!
I need this now :-)
I need this now :-) themselves can u say how did u do it? Where and what code did u put?
Thanx
Drupal tips
For me, worked without the
For me, worked without the hash #
$form_state['redirect'] = 'user/register';This, overrides the default front page redirection and redirects to the user registration form to show the default message:
"Your password and further instructions have been sent to your e-mail address."
Drupal 6.22 + MySQL 5.0.77 + PHP 5.1.6