0

Is there a way redirect users after they cancel their accounts? I've configured my site to allow users to cancel their accounts without e-mail confirmation, but I want to be able to redirect them to a "goodbye" page to reassure them that their account was in fact cancelled.

In user_cancel(), though, account cancellation is performed with the Batch API. I tried adding a drupal_goto() after the call to batch_set($batch), but this forces the goto and the batch processing is not performed.

How can I redirect non-admin users after they cancel their accounts?

3 Answers 3

1

There are two fine ways to do it :

  1. With Rules : If you have installed it already then you must use this. Select the event "After a user account has been deleted". Check the conditions you want and add action "Page Redirect".
  2. With Hook : Write a hook_user_delete and add drupal_goto in your condition.
0

You mention batch and the profile/cancel form.

Taking a look at the Batch API docs, we see that when called via form, FAPI will handle the redirect. Leading to the conclusion that you could add a submission handler with hook_form_FORM_ID_alter for the cancellation form and set $form_state['redirect'].

This would probably be advantageous over hook_user_delete &| drupal_goto, as higher weighted modules may get ignored. You could use rules but unless you're already using it elsewhere that's a bit overkill.

0

If I am not wrong user_cancel_confirm_form_submit() tries redirecting user to profile page after account cancelation which might end up throwing page not found. Looks like $form_state['redirect'] needs to be overridden in custom submit handler.

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.