Create Placeholders for Input Fields

There are contributed modules that will help with this that are listed below. You can also use Form API's #attributes to add in an HTML5 placeholder.

Here's an example using Drupal Form API:

<?php
$form['my_textfield'] = array(
  '#type' => 'textfield',
  '#attributes' => array(
    'placeholder' => t('My placeholder text'),
  ),
);
?>

Contributed Modules:

Label Trash: https://drupal.org/project/label_trash Stylish and accessible option using jquery floatlabel.js Placeholder module: https://drupal.org/project/placeholder Module allows non-HTML5 compatible browsers to still display placeholders using a jQuery plugin Field Placeholder: https://drupal.org/project/field_placeholder Allows you to add and edit placeholder attribute text for certain field types in the field UI. Jquery Placeholder: https://drupal.org/project/jquery_placeholder Does the same thing as the Placeholder module but it has much fewer installs.

Tags

Article Type

General