Hi

I would like to delete a homepage field in a comment form. There are 5 field in a comment; your name, email, homepage, subject, and comment. I just want to keep name, email, and comment.

I could erase subject field by changing the setting at the admin menu, but for homepage field, I suppose I need to modify a comment.module, but I am not sure how to edit it.

Any help would be greatly appreciated.

Thank you.

Takaki

Comments

SabbeRubbish’s picture

Hi Takaki,

As a default I think there are only 2 fields for comment: Subject and Body.
So obviously, you don't need to edit comment.module.

It seems you have may have module installed to configure the way people comment on your posts, which adds extra fields to the comments. Try to identify that module and configure it.

Hope this helped,

SabbeRubbish

takaki’s picture

Hi SabbeRubbish,

Thank you for your help.

I should have said that this is for anonymous user. I set my drupal to accept a comment from
anonymous. Then the comment form include those fields I mentioned in my original post.

I have installed only one module which is muti-ping sites module and I do no think it is related to comment field.

Thank you.

Takaki

somes’s picture

Long shot but I think it should work

create a node-comment.tpl.php and test it to see if it over writes the default comment node then you can code the parts of the comments that you would like to appear

run a search on google for "node-comment.tpl.php"
see if that helps

takaki’s picture

Hi Somes,

I suppose you meant this: http://drupal.org/project/nodecomment

Sounds like it can do what I want, but I am more lean towards editting a comment.module
because deleting one field from the comment form should not be that difficult.

Anyway, I will try this if there is no other way.

Thank you.

Takaki

VM’s picture

Just a note that altering a core.module while possible, makes it a pain to upgrade or update, as all changes will need to be done again.

If you really want to remove this from the core comment module, I believe you can look for the form array. search the code using homepage as your search term, find the form array and comment it out, it may be in two places.

SabbeRubbish’s picture

I agree with VeryMisunderstood,

Don't change the core modules at any cost! It will make an upgrade not only time-consuming but very discouraging, which would make you not update and leave some security bugs and such in...

Anyway, overriding the template seems like the best shot to me, you can easily migrate and upgrade that code. Of course, you will have to do some coding and take a look at the form API, but the gain compared to editing the core module is great I think.

I though I had a solution at the beginning of this post, but I've lost it...

SabbeRubbish

takaki’s picture

Then I will look into overriding the template approach.

Thank you all for your advice!

Takaki

somes’s picture

After reading you email again I think what your looking at doing is stopping the field from appearing at all in the "form" and not just removing it from the comment node

to do this I think you'll have to override the form API that outputs the form field I haven't tried anything like that

http://drupal.org/node/124849
ie edit the comment_form_alter

by the way how did you manage to enable the home page - you can disable it also, it doesnt appear on a virgin installation of 5

do let us know how you get on

bgilday’s picture

Takaki -

Were you able to remove the homepage field? If so, what approach did you use? Any details would be appreciated. I would like to do the same thing on one of my sites.

Thanks.

Brian Gilday
Municode
www.municode.com

takaki’s picture

shifthappens,

Sorry, I have not cheked this thread for a long time... and I have not tried this.

druvision’s picture

Once, in the last months, I've seen a generic module which gives a GUI to hook_form_alter to remove/hide fields but I don't remember it's name.

Please advise

Thanks in advance,

Amnon
-
Professional: Drupal Israel | Drupal Development & Consulting | בניית אתרים
Personal: Hitech Dolphin: Regain Simple Joy :)

druvision’s picture

I've now found formfilter - it is a really great module and allows to remove hidden form fields and collapse extra definition below the form.

daveander’s picture

add the following to your template.php file

function phptemplate_comment_form($form) {
   return _phptemplate_callback('comment-form', array('form' => $form));
}

create a file called comment-form.tpl.php


<?php //comment-form.tpl.php 

  $form['homepage'] = null;
  print drupal_render($form);

?>

Rob T’s picture

This worked as needed. Thanks.

IGadmin’s picture

Replace 'drupal_render' in line 4 of the comment-form.tpl.php with 'form_render'.

I incorporated this change on 4.7.6 with the above tweak, and it's working great.

codevelopment’s picture

Worked for me too, though I don't understand why it works.

scottpayne’s picture

Hi,

I managed to do this with a custom module, in the form_alter hook:

global $user;
if (!$user->uid && $form_id == 'comment_form') 
{
    unset($form['homepage']);
}

I'm a bit of a PHP newbie so I don't know if this has any repercussions, but I think it's a bit cleaner than editing core module stuff.

cakka’s picture

Takaki, i am searching the comment module with 5 field like you said. Can you give me about the name and download link ?
I get some problem when searching , the information that i get is not specific like i need. So i am being confused about what the module name.

Thanks

yoda-fr’s picture

I do that with css :
#edit-homepage-wrapper{
display:none;
}

it works form me!

Valkyri9’s picture

Thank you, @yoda-fr - I added this to the fresh.css file of my Zen subtheme and that immediately resolved this issue for me. Greatly appreciated!

OnlineWD™’s picture

I tried this twice http://drupal.org/node/147502#comment-286019 and it does not work with latest version of Drupal, does nothing. I really need this as I'm using the comments as a contact form for specific nodes. The homepage field is irrelevant, any ideas?

wnicklin’s picture

Lullabot discusses a couple of techniques to modify forms: http://www.lullabot.com/articles/modifying-forms-5-and-6">Modifying Forms in Drupal 5 and 6. I followed their theme override instructions to remove the homepage field from the comments form on a Drupal 6 installation, and it worked well for me.

First register the override in your template.php file (my example uses a zen subtheme):

/**
 * Implementation of HOOK_theme().
 */
function YOUR-THEME-NAME_theme(&$existing, $type, $theme, $path) {
  $hooks = zen_theme($existing, $type, $theme, $path);
  $hooks['comment_form'] = array('arguments' => array('form' => NULL));
  return $hooks;
}

Then, create a function specific for the comment form in your theme (also in template.php), with code to suppress the homepage field:

function YOUR-THEME-NAME_comment_form($form) {
  $output = '';
  unset ($form['homepage']);
  $output .= drupal_render($form);
  return $output;
}

Of course, make sure to change "YOUR-THEME-NAME" to the name of your theme. In D6, also need to clear the cache under admin/settings/performance to make sure the site recognizes your changes.

robertdjung’s picture

I thought there was an error with your wnicklin's code, but checking my PHP error log, I noted that my zen subtheme already had

THEMENAME_theme{
}

defined! Therefore I needed to add just

  $hooks['comment_form'] = array('arguments' => array('form' => NULL));

to the previously defined over-ride.

Thanks for the code help, and I hope this detail helps someone else.

dsanchez’s picture

This worked for me. Just make sure to delete this line if you are not using the Zen theme (otherwise it will cause Warnings)

$hooks = zen_theme($existing, $type, $theme, $path);

OnlineWD™’s picture

Got it to work, think I got it from this topic some where don't know but am using custom module ..

<?php
// $Id: customcomments.module

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


/**
* Unset these form elements from the comment_form using hook_form_alter
*/
function customcomments_form_comment_form_alter(&$form, &$form_state) {
  unset($form['_author']);
  unset($form['_homepage']);
  unset($form['homepage']);
  unset($form['comment_filter']['comment']['#title']);
}
robbin.zhao’s picture

This is great, using form_alter hook, but please add check

function {module_name}_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'comment_form') {
unset($form['_author']);
unset($form['_homepage']);
unset($form['homepage']);
unset($form['comment_filter']['comment']['#title']);
}
}

Rhino’s picture

I really do not want the Homepage field in the comment form, and none of the solutions found in the forum are working for me. Is there a new way to do this in Drupal 6?

casperloc76’s picture

Copy and paste this code into your template file.

/**
* Implementation of HOOK_theme().
*/
function THEMENAME_theme() {
return array(
	'comment_form' => array(                        
      'arguments' => array('form' => NULL),
    ),
  );
}

Remember you can only have one instance of HOOK_theme in your template file so combine this with your existing one.

Then insert this piece of code below and change to your needs

// theme the comment form
function THEMENAME_comment_form($form) {
  // Make the text-area smaller.
  $form['comment_filter']['comment']['#rows']   = 5;
  // Change the text-area title
  $form['comment_filter']['comment']['#title']  = t('Your message');
  // Remove input formats information.
  $form['comment_filter']['format'] = NULL;
  // Removes homepage field
  unset($form['homepage']);
  // Removes preview button 
  unset($form['preview']);              
  return drupal_render($form);
}
Rhino’s picture

Ah, so that's what I was doing wrong. Thank you for your help.

HenryLTV’s picture

Thanks for the code @casperloc76. Your HOOK_theme solution worked to unset the "Homepage" field from the form and it no longer shows.

But the issue I have now is that if you set the "Anonymous poster MUST leave contact information" option in the "Comment Settings" of the desired Content Type (ie. Forum or Blog), the form will never submit since "Homepage" is still a required field for the POST. I have this setting b/c i'd like to require the user to enter their "Name", but neither display NOR require the "Homepage" field.

Any suggestions for doing this in the theme?

Or is writing a custom module defining hook_form_alter the only option?

Thanks!

msathesh’s picture

Thanks @wnicklin.. Your solution worked for me in a drupal 6.x installation.. Thanks..

HS’s picture

Add this to your CSS:

#edit-homepage-wrapper {
display: none;
}
Vako’s picture

This CSS option didn't work for me. Note that the home page field is not visible to registered users, only anonymous users see it and I want to remove it just because it is a spam magnet.

VM’s picture

have you inspected the element with firebug to make sure the CSS id or class isn't changed in your theme?

Vako’s picture

Yes I did and it says: id="edit-homepage"
I have tried it as #edit-homepage and #edit-homepage-wrapper but the field is still there.
I am using pixture-reloaded theme and putting this code in the style.css file.

VM’s picture

and you've cleared the drupal cache?

without a link to the site it's difficult to aid with CSS issues.

Vako’s picture

Yes, I cleared the cache as well and days passed from the changes.

the following is a link where you can see the Homepage field still visible:
http://www.keghart.com/comment/reply/2773#comment-form

or try any other link on that site.

Thanks for the fast responses.

VM’s picture

#edit-homepage-wrapper {
display: none;
}

works directly in firebug even with the sites CSS aggregation turned on.

Where are you placing the override?

Vako’s picture

I am using the pixture-reloaded theme and putting this code at the beginning of the style.css file.

VM’s picture

overrides should go at the end of style.css to ensure that they override instead of being overridden.

As a best practice custom CSS and CSS overrides should be contained contained in a custom.css file which is defined last in the theme info file.

Vako’s picture

Thanks for the tips, that makes sense in several ways. I did move it to a separate css file and did a reference to it in style.css also I moved the code to the end of the style.css and in both cases the homepage field was still visible. (caches cleared).
The reason I am trying to eliminate the Homepage field is because the spambots keep injecting links to it. If this code will just hide the field from us but the bots will still be able to use it, then no need to change anything. The whole field needs to be completely taken off and I think that can be done only in the core?

What would you recommend?

I am using anti-spam modules, but the only ones that keep sneaking-in are the ones that are able to inject links in the Homepage field.

VM’s picture

I've no idea what you're doing incorrectly but I can remove the field on your site using firebug and the CSS I've provided (you should be able to do this step as well.). Looking at your site again, I don't see the CSS given being used in your aggregated CSS files. Perhaps you should disable CSS aggregation, clear the database cache and test again.

Vako’s picture

I have disabled the cache completely and cleared it. Still the same issue.
You can view the style.css file at this link.
maybe you can pinpoint the issue? thanks a lot for all your help.

VM’s picture

have you tested in firefox or chromes dev tools as instructed?

to illustrate that if used properly the CSS given does remove the homepage field see: http://i136.photobucket.com/albums/q189/VeryMisunderstood/Drupal%20Forum...

utilize pastebin and set the syntax highlighting to CSS to maintain readability.

Vako’s picture

I believe you that it does, if done properly and when I inject it manually in Firebug I can see it work, but putting it in the style.css has no effect at all. Can you inspect my css file and let me know if there is a conflict there perhaps? the link is in the previous post.

VM’s picture

syntax is fine. But it's definitely not being used. Are you sure this is the correct style.css file? If you backuyp the file following by uploading a blank style.css file what happens?

If you've changed the colors of pixture reloaded using the color picker it's possible that the changes aren't being pushed to the file stored in the files folder. In this case, perhaps deleting the currently utilized custom files and resetting the colors to generate new files will aid.

As an aside you shouldn't be altering style.css directly over the long term since it is a file that will be replaced if/when the theme is updated.

Vako’s picture

You are right, there is another css file called layout.css and it's working with the code in that file.
But the spammers are still able to inject the URL links to the same field. I have to find another solution to completely remove the field, probably from the core (yuck!)
Thanks a lot for your constant follow-ups and solution. Much appreciated!

VM’s picture

because hiding the field with CSS doesn't actually remove it from the form. while out of site it is still accessible to a bot or to a user who knows how to unhide the field by removing the CSS. Using hook_form_alter in a custom module removes the field from the form in total rather than hiding it.

Vako’s picture

Creating a module is out of my expertise, so I have to live with what I have. Thanks for all your help.

govindtotla’s picture

I did this by editing my core module. Added these lines just before the output return in module/comment/comment.module function comment_form() .
/* Unset the comment fileds . */
unset($form['homepage']);
unset($form['mail']);
unset($form['preview']);
unset($form['admin']['homepage']);
This is just a patch but worked for me.

Elijah Lynn’s picture

This is not recommended. There are solutions above that are the correct way to do this. Hacking or editing core will cause you problems when you upgrade.

-----------------------------------------------
The Future is Open!

mengi’s picture

For Drupal 7 add the following code to your themes template.php file. Replace THEME with your themes name.

function THEME_form_comment_form_alter(&$form) {
  $form['author']['homepage']['#access'] = FALSE;
}

Setting the homepage to NULL will throw a php validation error.

If you want only to edit a certain content type (example I am using is for blog content type), replace with

THEME_form_comment_node_blog_form_alter

Credit goes to http://www.digett.com/blog/05/26/2011/how-theme-comment-form-drupal-7.

himagarwal’s picture

@mengi

Thanks, it worked like a charm in Drupal 7. Code tested and verified.

Nicolas Bouteille’s picture

Perfect thx !

On second thoughts I put it in a custom module where I put all these little modifications because it is something that is not related to way my site looks like, I don't want it to re-appear the day I change the design.

hectorplus’s picture

Thank you! Worked like a charm! I am using zen theme

quirogapj’s picture

Thanks a lot! It works in Danland theme.

Regards,

dunkin007’s picture

hi, i am having the same problem in D7. however, it didn't exist earlier, just popped after i installed mollum. am i on the right track? does mollum have any option to disable this field? thanks.

Richard Buchanan’s picture

Just in case anyone wants to know where the homepage field comes from, visit admin/structure/types/manage/[content type]. In the comment settings vertical tab, there is a select option for anonymous commenting. Selecting "Anonymous posters must leave their contact information" or "Anonymous posters may leave their contact information" causes the email and homepage fields to show.

If you are okay with users just entering their name, subject (if enabled), and comment, then you can select "Anonymous posters may not leave their contact information".

If you are just looking to remove the homepage field but leave the email field enabled for Drupal 7, I would go with what mengi said.

joshuautley’s picture

Thank you. You comment helped at least understand how it came to be. I still don't want the homepage filed like the others. Sure would be nice to specify this without having to mess with the .tpl but not a big deal.

Josh Utley, President & CEO
Intrepid Network Inc. | Multimedia Services & Business Solutions

"Our mission is to provide a more personable multimedia service along with the highest quality business solutions."

cfischer50’s picture

My theme (Adaptive Theme subtheme) has a setting for Custom CSS (Layout and General Settings - in Extensions). I found this approach solved the problem a repeated subject display in my forums. And it works for removing the Homepage field in the Comment view for Anonymous users too. I used Developer Tools in Firefox to find the class name to use.

.form-item-homepage
{
display: none;
}
VM’s picture

the above wouldn't stop bots or anyone with any knowledge of CSS that thought to unset the definition and re-expose the field.

VM’s picture

Gorecmagic’s picture

Yes, I agree. This decision will not save you from the bots. I had such difficulty when I did it via CSS. Bots are not watching the page, they scan the DOM. Need to remove the code programmatically. I decided it this way, I put this code in template.php my theme:

function NAME_THEME_form_comment_form_alter(&$form, &$form_state) {
    $form['author']['homepage']['#access'] = FALSE;
}

"NAME_THEME" - replace on the machine name of the theme.