Where to remove "Your name: " when posting new comment?

Comments

justageek’s picture

from the form, or just not show this information when displaying comment?

mindgarden’s picture

When posting a new comment, right below the "Post new comment" and before the comment textbox, there is the:

Your name:
username

(this is for logged in users, as I don't allow anonymous comments)

How to hide this line? I use the acquia marina theme.

Thank you.

dnewkerk’s picture

I'm interested in this too, so subscribing. In my case I'd like to remove it for logged in users but still allow Anonymous comments to enter their name (for logged in users, showing the info is redundant).

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

dnewkerk’s picture

It was a bit painful to figure out, as I'm not a very good programmer yet and am quite mystified by all things FormAPI haha... but the following code seems to work for me. I figured it out through a combination of the "Changing Forms with hook_form_alter()" pages of the "Pro Drupal Development" book, as well as looking up the code in comment.module... aaaand plenty of searching on the forum. What you do is make a little module to paste this bit of code into (this is common practice for a Drupal site... you make a small "personal" module where you can drop in various functions and bits of code to modify things when they can't be done on the theme layer... I believe most people call this their "Site" module, so I named my module "Site"):

First make a folder at sites/all/modules/site which is where you will save the following two files.

Make a file called site.info and paste in this:

name = Site
description = Custom functions for this site.
core = 6.x
version = "6.x-1.0"

Make a file called site.module and paste in this:

<?php
// $Id: site.module

/**
 * @file
 * Custom functions for this site.
 */


/**
 * Unset these form elements from the comment_form using hook_form_alter
 */
function site_form_comment_form_alter(&$form, &$form_state) { 
  unset($form['_author']);
  unset($form['comment_filter']['comment']['#title']);
}

In the above code I also unset the "Comment:*" title that shows right above the main textarea of the form, since I felt it was not useful due to there already being the "Post new comment" or "Reply" text (depending on the context) above the form (not to mention it's completely self-explanatory without the additional text).

Go to your modules page and the Site module will show up. Enable it and go view a comment form to make sure it worked.

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

paul-drupal’s picture

Works perfectly. Thanks a lot. Looks like that "Pro Drupal Development" book might be a good investment.

mindgarden’s picture

It works perfectly. Good job.

Thanks.

dnewkerk’s picture

Glad to help. I have added this to the Handbook: http://drupal.org/node/368776

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

KorbenDallas’s picture

Thanks worked great. For D7 instead of:

/**
* Unset these form elements from the comment_form using hook_form_alter
*/
function site_form_comment_form_alter(&$form, &$form_state) {
  unset($form['_author']);
  unset($form['comment_filter']['comment']['#title']);
}

this is what worked for me, YMMV:

/**
* Unset these form elements from the comment_form using hook_form_alter
*/
function site_form_comment_form_alter(&$form, &$form_state) {
  unset($form['author']['_author']);
}
doutu111com’s picture

unset($form['author']); work too
unset($form['comment_filter']['comment']['#title']); not work for Drupal 7.
many perfects of Drupal 6 are gone, sometimes D7 drive me crazy...but fundamental is better.
remove Comment * , my workaround is:
label[for="edit-comment-body-und-0-value"] {
display:none;
}

Scunt’s picture

Thanks! Thats the first time i've 'created' a module and it worked perfectly.

x

pankajshr_jpr’s picture

Thanks works like charm