Community Documentation

Add user signature to new forum topic (or other node body)

Last updated March 11, 2007. Created by pwolanin on June 26, 2006.
Log in to edit this page.

The illustrated example below is a mini module that automatically adds the user signature to any new forum topic that they post. However, the same technique can easily be adapted to add some default text to any new node of a specific type or to all new nodes. See the API documentation for hook_form_alter, forum_form, and comment_form to understand how this works.

As a use case, this code may satisfy those who think it's inconsistent that comments get signatures, but not the forum topic that serves as the first post in the thread.

Save the code below as forumsig.module (but remove the closing ?>).

<?php
// Tested with Drupal 4.7.2- do not use with Drupal 4.6
/**
* Implementation of hook_help().
*/
function forumsig_help($section) {
  switch (
$section) {
    case
'admin/modules#description':
      return
t('Adds user signature to new forum topics');
  }
}

/**
* Implementation of hook_form_alter().
*
* Adds the current user's signature as the default text for any new forum topic.
*/
function forumsig_form_alter($form_id, &$form) {
  if (isset(
$form['type']) && ('forum_node_form' == $form_id)) {
    global
$user;  
    if (
$form['body_filter']['body']['#default_value'] == ''){
     
$form['body_filter']['body']['#default_value'] = $user->signature;
    }  
  }
}
?>

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.