Community & Support

How can I delete a homepage field from a comment form?

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

Hi Takaki, As a default I

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

Hope this helps,

SabbeRubbish

Hi SabbeRubbish, Thank you

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

Long shot but I think it

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

Hi Somes, I suppose you

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

=-=

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.

I agree with

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

Hope this helps,

SabbeRubbish

Then I will look into

Then I will look into overriding the template approach.

Thank you all for your advice!

Takaki

just had another look at this

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

Were you successful?

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
Aha Consulting, Inc.
www.ahaconsulting.com

shifthappens, Sorry, I have

shifthappens,

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

Generic module to hide/remove form fields?

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 :)

Check formfilter

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.

One way to do it

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);

?>

This worked as needed.

This worked as needed. Thanks.

If using a version prior to 5.0...

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.

Worked for me

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

Another way

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.

What the module?

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

I do that with css

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

it works form me!

Simple and effective CSS option

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!

I tried this twice

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?

Lullabot discusses a couple

Lullabot discusses a couple of techniques to modify forms: 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):

<?php
/**
* 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:

<?php
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.

@wnicklin I tried your code,

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.

This worked for me. Just make

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);

Got it to work, think I got

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']);
}

This is great, using form_alter hook

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']);
}
}

I really do not want the

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?

This might help you

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);
}

Ah, so that's what I was

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

Thanks for the code

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!

Thanks @wnicklin.. Your

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

Add this to your

Add this to your CSS:

#edit-homepage-wrapper {
display: none;
}
nobody click here