Tuesday 31 December 2013

How to make comment form look good in Drupal 7

What:

Drupal 7

Problem:

Comment form in Drupal doesn't look very appealing, it needs few tweaks.

Solution:

Paste below code in your template.php file, remember to replace word TEMPLATE with your template name. Clear all caches after applying changes.

**********************************
* Comment form changes
**********************************
function TEMPLATE_form_comment_form_alter(&$form, &$form_state) {
 // dpm($form);  //shows original $form array, if you have devel module installed
  if ($form['is_anonymous']['#value'] == FALSE) {
    $form['author']['#access'] = FALSE;
  }
  $form['author']['homepage']['#access'] = FALSE;
  $form['comment_body'][LANGUAGE_NONE][0]['#attributes']['placeholder'] = 'Comment...';
  $form['comment_body']['#weight'] = -10;
  $form['author']['name']['#attributes']['placeholder'] = 'Guest';
  unset ($form['comment_body'][LANGUAGE_NONE][0]['#title']);
  unset ($form['author']['name']['#title']); // Remove label for anonymous users
  unset ($form['subject']);

  $form['comment_body']['#after_build'][] = 'TEMPLATE_customize_comment_form';
}
function TEMPLATE_customize_comment_form(&$form) {
    $form[LANGUAGE_NONE][0]['format']['#access'] = FALSE; // Note LANGUAGE_NONE, you may need to set your comment form language code instead   
    return $form;
}

Comment  form before and after


No comments:

Post a Comment