Hello,

I have set up a content type that allows users (and anonymous people) to upload files and have them connected to their profiles. I want the form to take them back to their refering page after submit. To do this, I set up a custom module to implement hook_form_alter and a custom submit function to redirect users back to their refering page.

my_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_files_node_form') {
    if(isset($_SERVER['HTTP_REFERER'])) {
      $form['return_path']['#default_value'] = $_SERVER['HTTP_REFERER'];
    }
    $form['buttons']['submit']['#submit'][] = 'my_module_redirect_form_submit';
  }
}

function my_module_redirect_form_submit($form, &$form_state) {
  $form_state['redirect'] = $form['return_path']['#default_value'];
  drupal_get_messages();
  drupal_set_message("Thank You! Your file(s) have been successfully uploaded.");
}

This works fine for anonymous users, but when someone is logged in, they still get redirected back to their profile page. Is there a better solution?

Thank you for any tips!

- Matt