Redirect to last page when overlay comment-form is used

678 Views Asked by At

I've got a view (phase4) with some custom content type content in it, where the users may comment on.

When the users want to comment, the comment form should appear in a modal form. I solved this by using the admin overlay. Adding following function to my custom module:

    function phase2_admin_paths_alter(&$paths) {
        $paths['comment/reply/*'] = TRUE;
    }

and using following link:

<a href="<?php print base_path(); ?>comment/reply/<?php print $fields['nid']->content; ?>">Comment</a>

to open the comment form in a modal way. So far so good... but....

How do I redirect the user back to the page, the user was coming from. I know that I have to overwrite the #action of the form in the template_form_FORMID_alter, like

$form['#action'] = $lasturl;

but how do I get the last url, so that it is reusable (so hardcoding the url isn't an option)?

My first idea was that I transfer the last url by adding it to the url as a $_GET-parameter, but it looks like this:

www.example.com/phase4#overlay=comment/reply/161%3Furl%3Dphase4

I also tried it with drupal_get_destination(), but either with no success, because of the tranformation of the "?" and the "=" in the url.

Are there other ways to find out where the user was coming from?

Note: phase4 isn't the alias of node 161. Phase 4 is a view, where node 161 is an element of.

Cheers Tom

1

There are 1 best solutions below

1
On

You have to use the drupal_get_destination() function with l() function to create such links.

$destination = drupal_get_destination(); // Store current path

<a href="<?php print base_path(); ?>comment/reply/<?php print $fields['nid']->content . "?destination=".$destination; ?>">Comment</a>