3

I have a case where authenticated users can Vote a content many times.

I want a button at the top of the Node saying Vote This and when the users click the button it'll ask for confirmation Do you really want to Vote ?. When confirmed, he'll be redirected back to the same page, and be able to click the button again. However, in the backside, I want to record the time of voting and the user who voted it. Not necessarily the vote count, but just date/time and person.

I tried this with the Flag and Global Flag modules, but the issue is: once flagged, it can only be unflagged.

I also tried Fivestar module, with just one star (which I can change it to a button via CSS), but it doesn't ask for confirmation. It doesn't record the date/time either (I might be wrong here, but playing around with Fivestar, I didn't find a configuration option).

There must be something with VotingAPI which might be useful in my case, but I am unable to identify how to satisfy these conditions. I am seeking guidance.

Update: In addition to @Adam Balsam's answer to have confirmation I did

Use jQuery to add id to the link like: (I only have one vote in node)

$('.plus1-link').attr('id', 'vote-plus');

Then added jQuery confirm dialog like:

$('#vote-plus').click(function(e) {
               var cnf = confirm('Do you really want to vote?');
               if(cnf === false) {
                   e.preventDefault();
               }
            });

It might not be the elegant solution, but this how I solved my confirmation dialog option.

1
+50

Use the Voting API module with the Plus1 module (dev version). Working demo can be found here.

Voting API allows for immediate vote rollover as of 7.x-2.11. You just need a front end module that uses Voting API to allow your users to vote and Plus1 seems to do the trick.

  1. Enable Voting API and on the module admin page (/admin/config/search/votingapi -the module maintainers need to update their hook_menu() implementation) select immediately for Anon and Registered User vote rollover.
  2. Enable the Plus 1 module (requires ctools as a dependency). Use the dev version as the alpha version seems to have some permissions issues.
  3. Select the content types you want to allow users to vote on on the Plus1 admin page (admin/config/user-interface/plus1).
  4. Give Anonymous and Authenticated users access to the "Vote on nodes" permission.

The Voting API module will take care of recording the time of the vote and the user who cast it. Take a look at Lullabot's votingapi documentation. Specifically votingapi_select_votes().

The Plus 1 module comes with some stock JS and CSS to cast the votes via AJAX and provide some styling. But they also allow you to exclude those files from the admin interface if you want to create your own experience.

  • This is really really cool.... I tried it and this is the one that I have been looking for. However I am stuck in confirmation request, if I could add confirmation/modal confirmation (preferred), then it'd do all the good for me. – user12947 Nov 8 '13 at 9:48
2

Here's something you could try.

Create a content type, Vote. Add an Entity Reference field (to link the vote to the relevant node).

Then, allow users to vote with flags. When a user flags the content, use a Rule that goes something like this:

  • Event: Node is flagged
  • Action 1: Create an entity, a node of type vote (Author: logged-in user, also make sure to set the entity reference field value to the current node)
  • Action 2: Unflag the node

This way, the user will be able to flag the node multiple times and each time a vote node will be created that will include the date and time of each vote.

1

There is a patch for the votingapi module that allows you to control the vote rollover time for both anonymous and authenticated users. You can set the rollover time to zero seconds effectively enabling users to vote as often as they like.

Use the dev version of that module (or apply the patch manually) in conjunction with the Vote Up Down module. This setup will allow you to enable users (authenticated or anon) to vote unlimited times on content.

As far as the "Do you really want to vote?" confirmation, you'll probably have to write a small module or just a JS snippet to intercept the click and execute it on confirmation.

Update:
It looks like that patch made it into the 7.x-2.11 module back in March. So as long as you're using that branch, you should have this functionality already. Just se both Anon and Auth rollover to "Immediately" on the module admin page.

  • I think this is of potential use, but I get hell lots of error in Vote_up_down module. I also tried using Dev version, which offers extra configuration to set the vote in Node, but when I enable the module, It just screws the whole site. Have you used this personally ? – user12947 Nov 7 '13 at 11:16
  • Yeah, I've used vote up down many many times with success. (I have a client that likes to run tournament-style brackets.) Try starting from a clean environment, e.g. development site with Bartik theme and only the modules needed to create this functionality, then port it piece by piece to your current environment to see where the conflicts/error are coming from. – Adam Balsam Nov 7 '13 at 13:01
  • @JhilkeDai After trying to set up a demo to confirm this answer, I realized you're correct. It doesn't look like the Vote Up Down module was ever fully ported to Drupal 7 and it does throw all kinds of errors. I guess I've only used it on old D6 sites. The good news is the functionality is there with the Voting API module. Swapping in the Plus1 module for the VUD module does the trick. See my new answer. This answer is still valid if someone ever gets around to fixing the bugs in the D7 version of the VUD module. – Adam Balsam Nov 7 '13 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy