Community Documentation

VotingAPI: A framework for voting and rating modules

Last updated February 10, 2012. Created by PGiro on June 13, 2006.
Edited by torotil, shopdogg, ericbroder, dajpanspokoj. Log in to edit this page.

VotingAPI is a flexible, easy-to-use framework for rating, voting, moderation, and consensus-gathering modules in Drupal. It allows module developers to focus on their ideas (say, providing a 'rate this thread' widget at the bottom of each forum post) without worrying about the grunt work of storing votes, preventing ballot-stuffing, calculating the results, and so on.

VotingAPI does four key jobs for module developers:

  1. CRUD: Create/Retrieve/Update/Delete operations for voting data. The simplest modules only need to call two functions -- votingapi_set_vote() and votingapi_get_voting_results() -- to use the API. Others can use finer-grain functions for complete control.
  2. Calculation: Every time a user casts a vote, VotingAPI calculates the results and caches them for you. You can use the default calculations (like average, total, etc) or implement your own custom tallying functions.
  3. Workflow: By integrating with Actions.module, VotingAPI can trigger workflow steps (like promoting a node to the front page, hiding a comment that's been flagged as spam, or emailing an administrator) when votes are cast and results are tallied. Modules can expose their own 'default' action sets and filter criteria to provide moderation and promotion systems.
  4. Display: VotingAPI integrates with Views.module, allowing you to slice and dice your site's content based on user consensus. It also provides convenience functions to format vote data for display to users.

If you're a Drupal user looking for a voting or rating module (rather than just a framework), or you're a developer looking for examples of VotingAPI based code, check out some of the following projects:

Modules that are no longer actively maintained (may be easy to update and have interesting ideas on how to write a VotingAPI module):

Comments

Documentation Lacking

Documentation is somewhat lacking for Voting API.

Fortunately, the inline documentation within the votingapi.module file is extremely helpful. Here is the Lullabot API page for it: http://api.lullabot.com/file/contrib/votingapi/votingapi.module/

Most developers that are implementing VotingAPI in their module need to take a look here: http://api.lullabot.com/votingapi_set_votes

Enjoy!

- Jeremy
Activism Labs

Links are helpful

Thanks for the direction

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.x, Drupal 7.x
Audience
Programmers, Site administrators
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.