The code in the edit doesn't work, because $form_state['values']
isn't present before the submit. This is the correct code:
function hiderating_form_alter(&$form, &$form_state, $form_id) {
global $user;
if ($form_id == "comment_node_article_form") {
if ($form['uid']['#value'] != $user->uid AND $form['uid']['#value'] != 0) {
unset($form['field_stars']);
}
}
}
Using dpm($form)
, I discovered that $form['uid']['#value']
returns the uid from the user who wrote the comment. The value is only different from 0 if a comment is edited. When a user writes a new comment, the uid from the form is 0. That's why the AND
in the second if
is necessary.