drupaldrupal-6drupal-fivestar

How to redirect to a page after a fivestar vote in Drupal with Rules?


Drupal 6.22 Fivestar 6.x-1.19 Rules 6.x-1.4 These modules were the latest as of this posting.

My goal is to redirect a user to a page when they vote on a node. Should be simple enough.

I've created a rule for when a user votes on a node. No condition. I've added an action to add a message to the log to verify the rule is being triggered. Which it is. Then adding an action to redirect to the homepage (for testing). The redirect never happens. If I check the option "Immediately issue the page redirect", the ajax vote never saves and just hangs at "saving vote...".

I don't think I'm doing anything wrong and will post this to the fivestar module issues. Has anyone else had this issue?


Solution

  • http://drupal.org/node/252859

    A "redirect to url ..." will definitely cause issues with Fivestar's AJAX voting mechanism. Here's what's happening:

    What normally happens: - User clicks on a Fivestar widget to rate. - AJAX request is made by the current page. - VotingAPI saves the vote. - Fivestar generates XML and prints the page. - The current page receives XML, then updates the voting widget with the new values.

    What happens with VotingActions: - User clicks on a Fivestar widget to rate - AJAX request is made - VotingAPI records the vote - VotingActions hooks in and says "oh I'm redirecting this URL" <-- Where things go wrong - Instead of returning XML to the calling page (which would update the votes), the original page gets back a full HTML page of wherever VotingActions redirected the page. - Fivestar doesn't get to generate it's XML, because VotingActions has ended the execution by using a drupal_goto().

    So I don't think it's a bug in either VotingActions or Fivestar, it's just a case of using two features in incompatible ways. To make this work, Fivestar would have to not be AJAX driven, instead reloading the page to save a vote.

    Fivestar provides a nice JavaScript hook that you can use to go to the next page. If you add JavaScript to the page that contains something like this:

    function fivestarResult(voteResult) {
        window.location.href = 'http://google.com';
    }