Skip to main content

Drupal 7 notes - Hiding unwanted form elements in comment forms

Posted on: Friday, 11 February 2011 @ 4:25pm
Blatting about
More specifically

Just so I don't drive myself completely insane again.

It's a fairly standard theming problem, you have your Drupal comment form rendering thusly:

Drupal comment form (in WANLN theme)

Your site is set to not allow posting by anonymous users, rendering the "Your name" field superfluous and you think the subject line looks ugly, is unnecessary or you just don't want users giving their comments subjects for whatever reason.

In Drupal 6, you do it like this.  In Drupal 7, it's easier but harder to find.  They're in the docs, but the docs are a bit of a mess still.

comment-wrapper.tpl.php

I'm either stupid or doing something wrong or both but I cannot for the life of e work out how to hide or unset those stupid formatting guidelines.  So css it is.

style.css (or whatever you call yours)

.filter-wrapper { display: none; }

No comments yet

Anonymous Tuesday, 15 March 2011 @ 3:45pm [Permalink]

The comment subject field can be hidden from the input form in the content type's comment settings. You still have to hide or theme it out of display though.

bek Tuesday, 15 March 2011 @ 11:40pm [Permalink]

It can indeed.  I suspect I wrote this before I realised that :) Thank you for the reminder!

Antti Tuppurainen Thursday, 17 March 2011 @ 10:13pm [Permalink]

You may hide the formatting guidelines in node.tpl.php

hide($content['comments']['comment_form']['comment_body']['und']['0']['format']);

bek Friday, 18 March 2011 @ 12:21am [Permalink]

Awesome, thanks for that Antti Tuppurainen!

capsx Tuesday, 3 January 2012 @ 12:30am [Permalink]
not working if submited comment has errors ...
bek Tuesday, 3 January 2012 @ 4:33pm [Permalink]

What's not working and what kind of errors?

Silv Wednesday, 6 February 2013 @ 10:11am [Permalink]
Where is node.tpl.php can you give me the path? I want to hide the "more information about text formats"
bek Wednesday, 6 February 2013 @ 10:33am [Permalink]

If you're using a custom theme you can add one, and then clear the cache, and Drupal will use it.  The default themes in /themes each have one I think, but hacking core should be avoided where possible :)

nature made fish oil Thursday, 4 August 2011 @ 11:24am [Permalink]

Hi there! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I'm getting sick and tired of Wordpress because I've had problems with hackers and I'm looking at options for another platform. I would be great if you could point me in the direction of a good platform.

bek Thursday, 4 August 2011 @ 2:10pm [Permalink]

I use Drupal for the blog (and pretty much everything).  Check any plugins you're using for security holes, I don't often hear about WP being constantly cracked but then again I don't pay close attention to other cms :)

Saad Sunday, 25 December 2011 @ 4:07am [Permalink]
in your CSS file add . before the class name, this may help a novice.like this:.filter-wrapper{  display: none;}
bek Sunday, 25 December 2011 @ 11:37am [Permalink]

I didn't even notice I'd left the . off.  Thanks for that :) Edited to put it back in and reformatted the code to look more codey while I was about it.

bassnoodle Wednesday, 14 March 2012 @ 11:30pm [Permalink]
In the drupal 7 admin, you can go to your "edit content type" page, and click on the "Comment Fields" tab in the upper right.  Then, click "edit" under the comment body field, and you can set the default of all comment fields to "plain text". The admin path would be, for example on a content type with the machine name "blog": admin/structure/types/manage/blog/comment/fields 
bek Thursday, 15 March 2012 @ 10:31am [Permalink]

I did this one with a minimal install so it only came with plain text.  I wanted them defaulting to the editor.

İbrahim Tuesday, 4 February 2014 @ 3:03pm [Permalink]
hello. i have a drupal website with articles. anonymous user comment some article but they give fake email address and ads (comment website field). how can i solve this problem? how can hide website field and verify email existence?thanks, 
bek Tuesday, 4 March 2014 @ 12:18pm [Permalink]

Hi! Sorry for taking so long to answer you.  You can use Honeypot and Mollom (either together or separately), the first one helps to cut down on spambots and the second one is a subscription based service (they have free basic accounts for personal blogs and small websites that don't get a lot of traffic if yours fits either of those criteria, otherwise their prices aren't bad) that compares what is posted to known spam material and if it decides it's spam it prevents the content from being posted, otherwise allows it through.

If you want to hide the website field you can use a display: none in the css (and this way you will also know if it's a bot or a person as a bot will fill it out anyway), or you can do a hook_form_alter on the comment form to remove it if there isn't a way to do it in the gui (you couldn't before and I haven't looked recently). I'm not sure how to verify email as I use both of the above on this site (and most of my other ones).

Hope that's helped (or better yet that you've already resolved this problem somehow :).

Padma Tuesday, 4 March 2014 @ 6:42pm [Permalink]
Thanks.This is a great article.
bek Tuesday, 4 March 2014 @ 10:14pm [Permalink]

Hope it helped :) Thanks for dropping by.

Mesin cutting … Sunday, 20 April 2014 @ 1:38pm [Permalink]
Hi.How to display author name with the name that visitor fill in? So it's not anonymous or else anymore.Thank's.
bek Sunday, 20 April 2014 @ 2:12pm [Permalink]

Hi :) I think that one might be up to the browser and the user to allow cookies (assuming they're not allowed to sign up accounts which would be the easiest way to get around that problem).  I vaguely remember there being a module for something like that possibly but it was a long time ago and I could be remembering wrong.  I'm not sure what you're trying to achieve specifically, would something like Comment Trust help?

Mesin cutting … Sunday, 20 April 2014 @ 2:44pm [Permalink]
Hi, thank's for response.What i mean is like i write in this comment, it's displaying the name that i write in the field Name (Like this one (Mesin Cutting Sticker)), but when i write a comment in my site even i write some name it's always say Anonymous for non registered user.*have a bad english. lol Thank's
bek Tuesday, 22 April 2014 @ 7:55am [Permalink]

Hm, I'm reasonably certain I didn't do anything special on that front.  Are you allowing cookies and scripts for that website? And are you using AJAX comments or any other comment/comment enhancing system?

Aaacab Saturday, 18 January 2020 @ 4:50pm [Permalink]
I am grateful to this blog site providing special as well as useful understanding concerning this subject.
thiwanga sandaruwan Friday, 24 April 2020 @ 8:38pm [Permalink]
Awesome tutorial for noobs like me. first thanks for that. if you are find a free backlink, traffic bot, ethical hacking or cyber security related thing you should go to <a href="https://secdevil.com">Secdevil.com</a> This is actually worl leading cyber security and ethical hacking blog. visit now https://secdevil.com

Add new comment

The content of this field is kept private and will not be shown publicly.