3

As I would like to allow users print their names with comments I added a new field called comment_name. To not have 2 fileds with name I used the code to unset filed "name" from comment.module

function user_add_node_form_comment_form_alter(&$form, &$form_state) {
unset($form['author']);
return $form;
}

But after adding a comment I receive an error message

Notice: Undefined index: name in function comment_form_validate() (line 2127 in file D:\sites\theme\www\modules\comment\comment.module).
Notice: Undefined index: mail in function comment_form_validate() (line 2140 in file D:\sites\theme\www\modules\comment\comment.module).
Notice: Undefined index: homepage in function comment_form_validate() (line 2143 in file D:\sites\theme\www\modules\comment\comment.module).

I guess it because I unset a form that has to validate if user logged in or not but don't know how to solve it.

P.S. Also I use the Ajax Comments Module

1 Answer 1

5

You should try this if you just want to hide the comment default name field !

function user_add_node_form_comment_form_alter(&$form, &$form_state) {
  $form['author']['name']['#access'] = FALSE;
}
2
  • thank you, your variant of function works, but if user user "preview button" before posting comment drupal returns an error: "Notice: Undefined index: format in function comment_preview() (line 2057 in file D:\sites\theme\www\modules\comment\comment.module). Notice: Undefined property: stdClass::$thread in function ajax_comments_entity_prepare_view() (line 375 in file D:\sites\theme\www\sites\all\modules\ajax_comments\ajax_comments.module)."
    – moto
    Commented Sep 26, 2012 at 5:39
  • well, it was my mistake in ajax comment module configuration. Thanks for help!
    – moto
    Commented Sep 26, 2012 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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