Drupal 7 - HTML 5 Placeholder in Comments Fields

BLOG

How to apply the HTML 5 Placeholder to your comment fields in Drupal 7. Using a function in template.php.

Put the following code in yout template.php. Change "THEME" with your theme name.

function THEME_form_comment_form_alter(&$form) { $form['author']['name']['#attributes']['placeholder'] = t( 'Name' ); $form['author']['mail']['#attributes']['placeholder'] = t( 'E-Mail-Addresse' ); $form['comment_body'][LANGUAGE_NONE][0]['#attributes']['placeholder'] = t( 'Kommentar' ); }

 

To complete this: here is a code that will also remove the Homepage field and textformating tips.

function THEME_form_comment_form_alter(&$form) { $form['author']['homepage']['#access'] = FALSE; $form['author']['name']['#attributes']['placeholder'] = t( 'Name' ); $form['author']['mail']['#attributes']['placeholder'] = t( 'E-Mail-Addresse' ); $form['comment_body'][LANGUAGE_NONE][0]['#attributes']['placeholder'] = t( 'Kommentar' ); } function THEME_filter_tips($tips, $long = FALSE, $extra = '') { return ''; } function THEME_filter_tips_more_info () { return ''; }