Introduction

I created the following snippet recently for a project where the client wanted help text for node TITLE and node BODY fields.

Step 1 of 2

Copy the following snippet into a custom projectname_overrides.module and modify projectname to suit.

If you don't already have a projectname_overrides.module setup for your project. See below for a simple module .info file you can use.

The following uses the node type variable so the help text is dynamic for each content type. You can obviously go further and have custom descriptors for specific content types.

<?php
/**
*  Adding help text to node title and body fields
*/

function projectname_overrides_form_alter(&$form, &$form_state, $form_id) {
  $form['title']['#description'] = '<p>' . t('Enter a title for the %type item.', array('type' => $form['type']['#value'])) . '</p>';
  $form['body_field']['body']['#description'] = '<p>' . t('Enter a description for the %type item. This should be at least ten (10) words.', array('type' => $form['type']['#value']) . '</p>';
}
?>

Step 2 of 2

Enable the module and refresh the node edit page. You may need to clear cache prior to this.

projectname_overrides.info file

Here's a projectname_overrides.info file you can copy and use if you don't already have a custom projectname_overrides.module set up.

; $Id$
name = Custom Overrides
description = Custom overrides module
core = 6.x

Notes

  • Tested by Dublin Drupaller July 2011 with drupal 6.x and pressflow
  • Please add a child page to this handbook page if you find an improvement or more efficient way of doing this

Comments

bgogoi’s picture

Hello!

This is what I was looking for D7. can anyone please port this for D7?

Thanks a lot

jasom’s picture

Also need this code for D7.

drupestre’s picture

Find here a drupal 7 version (replace modulename with your module's name) :

modulename.info

; $Id$
name = modulename
description = Custom overrides module
core = 7.x

modulename.module

/**
*  Adding help text to node title and body fields
*/

function modulename_form_alter(&$form, &$form_state, $form_id) {
  $form['title']['#description'] = '<p>' . t('Enter a title for the '. $form['type']['#value'] .' item.') . '</p>';
  $language = $form['body']['#language'];
  $form['body'][$language][0]['#description'] = '<p>' . t('Enter a description for the '. $form['type']['#value'] .' item. This should be at least ten (10) words.') . '</p>';
}

Hope it helps

jadhavdevendra’s picture

This module can be used to add help text to node title -
https://www.drupal.org/project/node_title_help_text

aniket.mohite88’s picture

You can use the "#attributes" setting to set a title attribute, which will display a given text as a tool-tip.

<?php
/**
*  Adding help text to node title as tool-tip popup using attribute "title"
*/
function projectname_overrides_form_alter(&$form, &$form_state, $form_id) {
$form['title']['#attributes'] = array(
    'title' => 'Custom text message that you want to set.');
    }
?>