I've got a form that starts a batch job. What's the right way to redirect them after it finishes? Calling drupal_goto() in my finish function?

4 Answers 4

drupal_goto('your/hookmenu/link', array('query' => array('destination', $_GET['destination'])));
  • Yeah, I know how drupal_goto() works I'm just curious if there's a better way, something like $form_state['redirect']
    – drewish
    Aug 7, 2012 at 14:42
  • I don't know a better one, but an alternative is header('Location: index.php?q=node"); But I will not use it personally. $form_redirect['redirect'] will not work outside a form context. So drupal_goto is the only robust way to do it.
    – Minty
    Aug 8, 2012 at 13:49

You can set 'redirect' in hook_batch_alter(). For example:

$batch['form_state']['redirect']['path'] = 'cart';
  • 1
    Do you have a sample for how that would work? It doesn't seem like the batch is a form.
    – drewish
    Sep 14, 2012 at 16:42

If you know the redirect path in the moment you start the batch, you can


See https://api.drupal.org/api/drupal/includes!form.inc/function/batch_process/7


i'm create link to form (created by form api) that runs the batch with get-parameter "?destination=myRedirectPath".

batch lanch on function form_submit() and take info about redirect after batch from url.

without "goto".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.