-1

How can I only allow the user to up vote or down vote a post once. This is the vote.tpl in the themes folder. What do I need to change?

<script type="text/javascript">
   $('.unlove').click(function () {
      var id = $(this).attr('entryId');
      if ($(this).hasClass('unloved')) {
         $(this).removeClass('unloved');
         ulikedeg($(this).attr('entryId'), 0, -1);
      } else {
         $(this).addClass('unloved');
         if ($('#post_love_' + id).hasClass('loved')) {
            ulikedeg($(this).attr('entryId'), -1, 1);
            $('#post_love_' + id).removeClass('loved');
         } else {
            ulikedeg($(this).attr('entryId'), 0, 1);
         }
Josh Mein
  • 28,107
  • 15
  • 76
  • 87
  • The `themes` folder of what framework? It looks like this code already does that. When a user "shows love" the link turns into a "unlove" link, so the user can only love it once. – Dutchie432 Apr 25 '12 at 14:37
  • ultragag.com here is the site i want user to can vote only one time per post but they can multiple times – user1354174 Apr 25 '12 at 14:44

1 Answers1

1

You will have to keep track of IF that user has voted on something, in your database (or wherever you store the 'votes').

On each page generation, you need to check what the user voted on, and mark the buttons with proper values. Either set a class 'already-voted' on a button, which would disable it from input, or some other method.

Jakub
  • 20,418
  • 8
  • 65
  • 92
  • 1
    No one is going to write your code for you. If you are modifying pre-written code (which it seems you are) - then tell us what you've tried. If you've tried nothing, than hire us to write your code. :) – Dutchie432 Apr 25 '12 at 14:37