Working with comment in Drupal

December 12, 2013


Adding comments to Drupal Content

Suppose, you want to add comment to Page content types. Now Go to content type edit section and then comment settings section and do the following

  1. Select Read/Writeradio in Default comment setting
  2. To hide subject field in comment form, then choose disabled in comment subject field.
  3. If you want to display name, email field in comment form, then choose “Anonymous posters must leave their contact information” in anonymous commenting
  4. Hit save content type to save these settings

Setting permission for anonymous user

Now go to permission page and search for comment module section and give permission to anonymous user

  • access comments
  • post comments
  • post comments without approval ( If you want to publish comments without admin approval )
  • Click save configuration

Setting up Restriction in user comment

For security reason, you must configure comment input format system. If you gave input format as full html permission, then user may enter untrusted data or harmful data to your sites. To do this go to : admin/settings/filters/defaults (drupal 6) and set “Filtered HTML” for anonymous user.

The anchor tag is default in Filter HTML. If you think it is harmful then configure it and remove tag from Filtered HTML. To do this first go to input format list page:admin/settings/filters (drupal 6) and click Filtered HTML configure link and then click configure tab . Under allowed HTML tags : remove

Finally click save configuration button.

Adding captcha to block spam

If you wish you may include captcha in your comment form. Adding captacha is one of the best way to project spam comment. For this download Captcha module. Install captcha and image captcha module, go to configuration page and add comment form

Restrict on Comment body characters

Now some extra configuration. suppose you want to restrict comment body to 128 characters. To do this write a small module and write the folloing code or you can download this from here and enable.

// drupal 6
// file
$Idcomment_limitation hasan hafiz Exp $
name "comment limitation"
description "Set character limits in comment body"
core 6.x
// comment_limitation.module file

// implements hook_form_alter()
function comment_limitation_form_alter(&$form$form_state$form_id) {
  if (
$form_id == 'comment_form') {
$form['comment_filter']['comment']['#maxlength'] = 128;
$form['comment_filter']['comment']['#length'] = 128;
$form['comment_filter']['comment']['#description'] = 'Max length 128 characters';
// print_r($form); exit;