technonaturalist

image link to hive image link to ko-fi

Drupal 7 notes: html5 placeholder text

posted on: Friday, 25 May 2012 @ 2:03pm in
tagged

Fairly straightforward. Mostly here as a reminder for how to do webforms; (example has a theoretical nid of 1 and a theoretical form field called “message” and the “submitted” part stymied me for a bit).

template.php

<?php 
function mytheme_form_webform_client_form_1_alter(&$form, &$form_state, $form_id) {
    $form['submitted']['message']['#attributes']['placeholder'] = t('Type your message here...');
} 
?>

Could also use a switch in hook_form_alter(). One of these days I’ll think about finding out if there’s any difference performance-wise in using a big switch with many form alterations or several smaller hook_form_form_id_alters.