Adding form placeholders to text input fields
That's an HTML5 placeholder, you can just add it as an attribute to any element and HTML5 enabled browsers will react accordingly:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'some_form') {
    $form['some_element']['#attributes']['placeholder'] = t('Placeholder text');
  }
}


A short recursive function like this might be handy if you want to automatically add placeholders for every textfield in a form (based on the field's title in this example):

function MYMODULE_auto_placeholders(&amp;$element) {
  if ( isset($element['#type']) &amp;&amp; $element['#type'] == 'textfield') {
    // set placeholder
    $element['#attributes']['placeholder'] = $element['#title'];
    // hide label
    $element['#title_display'] = 'invisible';
  }
  foreach (element_children($element) as $key) {
    MYMODULE_auto_placeholders($element[$key]);
  }
}


Then in your form alter function just call

MYMODULE_auto_placeholders($form);


That method will work for pretty much every textfield on a form, with the exception of those that are added in #process functions (like the alt and title textfields of an image field for example).