For what it's worth, I took a slightly different approach that might be useful. It isn't perfect, but works very well for me. I borrowed heavily from the solution here:
How to limit a user to one vote when using Fivestar?
But I didn't like changing my theme. I wanted to to it in the form alter, as I wanted to control things before they got to the browser (so other #validate solutions weren't right for me). Anyway, here is my approach:
<?php
function MYMODULE_form_alter($form_id, &$form, $form_id) {
switch($form_id) {
case 'comment_node_product_form': //Modifications to the voting for five star on comment forms
MYMODULE_fivestar_limit_votes($form);
break;
}
}
/**
* Function to limit votes on a particular node to one per user. Also requires users to be logged in to vote.
* This assumes that you are passing in a node as the entity for which the vote is recorded. That little bit would
* of course be more flexible if done differently.
*
* @param unknown $form
* @param string $voteTag
* @param string $entityType
*/
function MYMODULE_fivestar_limit_votes(&$form, $voteTag = 'rating', $entityType = 'node') {
$path = drupal_get_path('module', 'fivestar');
// These are likely added already, but no harm done just in case
drupal_add_js($path . '/js/fivestar.js');
drupal_add_css($path . '/css/fivestar.css');
$replacement = false;
$is_login = user_is_logged_in();
$nid = $form['#node']->nid;
$rating = votingapi_select_single_result_value(array(
'entity_id' => $nid,
'entity_type' => $entityType,
'tag' => $voteTag,
'function' => 'average',
));
$lang = $form['field_product_rating']['#language'];
$widget = $form['field_product_rating'][$lang][0]['rating']['#widget'];
if ($is_login) {
if (isset($rating)) {
$voting_message = "<div>You have already rated this.</div>";
$replacement = theme('fivestar_static', array('rating' => $rating, 'stars' => 5, 'tag' => $voteTag, 'widget' => $widget)) . $voting_message;
}
// The 'else' here is to leave the form alone.
}
else {
$fivestar_links = l('Login', 'user/login') . ' or ' . l('Register', 'user/register');
$voting_message = "<div>Only registered user can rate this content type.<br/>$fivestar_links to rate this content type.</div>";
$replacement = theme('fivestar_static', array('rating' => $rating, 'stars' => 5, 'tag' => $voteTag, 'widget' => $widget)) . $voting_message;
}
if ($replacement) {
$form['field_product_rating']['#type'] = 'markup';
$form['field_product_rating']['#markup'] = $replacement;
$form['field_product_rating']['#tree'] = false;
unset($form['field_product_rating']['und']);
}
?>