I implemented a profile screen that has the ajax popup for removing a buddy. When I remove the buddy the screen is redirected to the sites home page. Is there a way to change the destination of the redirect without modifying the module's code?

The redirect is being issued from /user_relationships/user_relationships_ui/user_relationships_ui.forms.inc in the ajax handler:

function user_relationships_ui_remove_ajax($account, $relationship) {
  //382668 makes sure a valid relationship id was supplied
  if (!$relationship->rid) {
    if (isset($_GET['ajax'])) {
      die();
    }
    drupal_goto();
  }
  $form = drupal_get_form('user_relationships_ui_remove', $account, $relationship);
  if (isset($_GET['ajax'])) {
    die($form);
  }
  return $form;
}

I noticed that drupal_goto is being called. From api.drupal.org , "you may override that behavior by setting a destination in either the $_REQUEST-array (i.e. by using the query string of an URI) or the $_REQUEST['edit']-array (i.e. by using a hidden form field). This is used to direct the user back to the proper page after completing a form."

Can this be done in this instance, if so how? Is there an alternative approach?

Comments

arcane’s picture

Similarly, when adding a buddy using the Ajax popup, I would like the redirect to stay on the profile being viewed. Currently the page redirects to a url like: relationship/6/request/1 which is blank and just has the drupal set_message

arcane’s picture

I'm hoping someone can get back to me, I'm hoping there's a method to do this without modifying module code....

alex.k’s picture

You can probably implement a hook_form_alter and add the desired destination parameter to the form. Then drupal_goto will pick it up as it looks for the parameter. I have not tried this approach, though.

arcane’s picture

Yes, that occured to me, I think I could target the form in the popup with the hook form alter, and change the '#redirect' parameter. I'll give it a try.

arcane’s picture

Yes, this approach worked on the targeted pop-up form.

alex.k’s picture

Status: Active » Fixed

That's cool, thanks for the follow up. If you could post the form_alter function you used here for the benefit of others that would be great.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.