I'd like to hide the Fivestar rating field (called 'field_stars') in my comment form when a user comments on a node on which he/she's already commented. I 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 tried to fix my problem, 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 ($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). What did I do wrong?
After debugging with @jerdiggity's code I get:
DEBUG: form id "comment_node_stuff_form" found. Debugging...
DEBUG: The code $flag->is_flagged($form["#node"]->uid, $user->uid) is returning FALSE.
(of course I get the DEBUG: final form structure: too, but that's way to long to paste here). I don't understand why the flagging isn't recognized, as it is stored in the database...
Try adding these debug values to get to the root of the problem (not on a live server, of course... Only in a development environment):