Hi everyone!

I have got hook_form_alter function in my module:

function dashboard_form_user_register_alter(&$form, &$form_state) {
  $form['#redirect'] = array('<front>'); // or $form['#redirect'] = '<front>';
}

This code does not working.
As I understood, after form submit, user should be redirected to the site front page, is not it?

Comments

to.stepan.kuzmin@gmail.com’s picture

...it does not working like this:

function dashboard_form_user_register_alter(&$form, $form_state) {
  $form['#submit'][] = 'dashboard_user_register_submit';
}

function dashboard_user_register_submit(&$form, &$form_state) {
  $form['#redirect'] = '<front>';
}
titouille’s picture

Hi,

try

$form_state['redirect'] = '<front>'

in the hook_submit handler

I had a strange behaviour with it too. the redirection wouldn't work and after setting a drupal_write_record in my code, it worked...

see this thread too : http://drupal.org/node/134000

hope this help you to find a solution ;-)

to.stepan.kuzmin@gmail.com’s picture

Thank you for answering, but this does not working too.

function dashboard_form_user_register_alter(&$form, $form_state) {
  $form['#submit'][] = 'dashboard_user_register_submit';
}

function dashboard_user_register_submit(&$form, &$form_state) {
  $form_state['redirect'] = 'dashboard/user/list';
}
to.stepan.kuzmin@gmail.com’s picture

Even, it does not work like this:

function dashboard_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'user_register':
        $form['#redirect'] = 'dashboard/user/list';
      break;
  }
}
to.stepan.kuzmin@gmail.com’s picture

This comment helped me: http://drupal.org/node/580144#comment-3368072

Just need to add

unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);

before

$form_state['redirect'] = 'dashboard/user/list';
titouille’s picture

Good to know the trick.

I have spent half a day with the same problem... No effective redirection, with $form['#redirect'], $form_state['redirect'], drupal_goto, etc...
And with addition of some line of code to complete my submit function, the redirection will perform, like magic... Ô_o not understand...

lookatthosemoose’s picture

Thanks for this tip. Had spent WEEKS debugging this issue.

aerozeppelin’s picture

Thanks a Million!