2

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?

3
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 '12 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 '12 at 13:49
6

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 '12 at 16:42
2

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

batch_process('my/destination/path');

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

0

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, privacy policy and cookie policy

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