1

The accepted answer on How to limit a user to one vote when using Fivestar? doesn't work for me, but the author hasn't provided a solution yet, so I felt this is worth a new question.

My goal is exactly the same as the one in the article mentioned above: I'd like to hide the Fivestar rating field (called field_stars) in the comment form when a user comments on a node on which he/she's already commented.

Is there another solution (for example with the Rules and Flags modules)?


Edit: I already have a flag called Commented on my site and a rule that flags a node on behalf of the commentator when someone commented on it (which works perfectly). I'd really like to use it to fix this problem. I tried something, based on the information I found here:

function hiderating_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  $flag = flag_get_flag('commented') or die('no "commented" flag defined');
  if ($form_id == "comment_node_stuff_form") {
   if ($form['#node']->uid == $user->uid OR $flag->is_flagged($form['#node']->uid, $user->uid)) { 
      unset($form['field_stars']);
    }
  }
}

Unfortunately, it doesn't change anything (I don't get any errors either).

0

In your node.tpl.php you should have the following code

hide($content['field_fivestar']);
print singlerating_print_rating($node->nid, $content['field_fivestar']);

I presume field_fivestar is the fivestar field you are using and not field_fivestar_rating

  • I tried that before and it doesn't work either. – Jeroen Nov 18 '13 at 17:42
  • What is the result you get when you add that code? – Mohammed Shameem Nov 18 '13 at 17:43
  • Nothing happens: no errors, no nothing. – Jeroen Nov 18 '13 at 17:44
  • could you do one thing add the following code in your node.tpl.php print "<pre>" . $content . "</pre>"; and send me the out put that you get in your screen. – Mohammed Shameem Nov 18 '13 at 17:49
  • Should something be displayed on the content pages? I can't see anything there... – Jeroen Nov 18 '13 at 17:58
0

I nearly had the answer in my edit. The code should have been

function hiderating_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  $flag = flag_get_flag('commented') or die('no "commented" flag defined');
  if ($form_id == "comment_node_stuff_form") {
   if ($form['#node']->uid == $user->uid OR $flag->is_flagged($form['#node']->nid, $user->uid)) { 
      unset($form['field_stars']);
    }
  }
}

So, the only thing that was wrong was $flag->is_flagged($form['#node']->uid. It should have been $flag->is_flagged($form['#node']->nid.

Many thanks to @jerdiggity on Stackoverflow!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.