Last updated July 14, 2011. Created by Dublin Drupaller on July 14, 2011.
Log in to edit this page.

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 '. $form['type']['#value'] .' item.') . '</p>';
 
$form['body_field']['body']['#description'] = '<p>' . t('Enter a description for the '. $form['type']['#value'] .' item. This should be at least ten (10) words.') . '</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

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Hello!

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

Thanks a lot

Also need this code for D7.

I ♥ Drupal.

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

<?php
/**
*  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

--------------------------
Share & Bon Marché