Community Documentation

Handling multi-line profile fields

Last updated September 6, 2009. Created by John Morahan on January 22, 2006.
Edited by bekasu, ronald_istos, Dublin Drupaller. Log in to edit this page.

PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

Description

This php snippet displays multi-line textfields. If the user has not specified anything, it displays nothing

Dependencies: profile.module

Usage

  • Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
  • Change the custom profile field name from profile_biography used in the example below. (Tip: In Drupal 4.x go to administer -->> settings -->> profile and in the second column it will give you the field name. In Drupal 5.x the profiles settings page can be found at administer -->> user management -->> profiles)
  • Tested and works with Drupal 4.5, 4.6, 4.7.x and 5.x
  • Make sure you us the snippet variation of the snippet that matches the version of Drupal you are using.
  • Change the div class names or the prefix text to suit.

works with Drupal 4.5.x and Drupal 4.6.x

<?php if($account->profile_biography): ?>
<div class="fields">Biography: <?php print check_output($account->profile_biography) ?></div>
<?php endif ?>

works with Drupal 4.7.x & Drupal 5.x

<?php if($account->profile_biography): ?>
<div class="fields">Biography: <?php print check_markup($account->profile_biography) ?></div>
<?php endif ?>

Tweaking the output

The check_markup function uses your site's default input format, which runs the text through the normal filters and (usually) does things like adding line and paragraph breaks, as well as filtering out any potentially dangerous code. This is how Drupal handles multiline profile fields by default. However, if you don't want all this extra functionality, you can call the necessary filters directly instead: _filter_autop for adding line and paragraph breaks (usually a good idea for multiline profile fields) and filter_xss to remove potentially dangerous code:

<?php if ($account->profile_biography): ?>
<div class="fields">Biography: <?php print _filter_autop(filter_xss($account->profile_biography)); ?></div>
<?php endif ?>

If you don't want the line and paragraph breaks, you can omit _filter_autop and use filter_xss by itself instead:

<?php if ($account->profile_biography): ?>
<div class="fields">Biography: <?php print filter_xss($account->profile_biography); ?></div>
<?php endif ?>

Comments

changes for D6 and D7

Hey Guys (and Gals),

Would love to see this documentation updated for modern versions of Drupal. I am working on some theming of D6 and D7, and some of this may no long be valid. I will try to post any changes I discover.

Thanks,
Scott

ScottSaywerCOnsulting.com

About this page

Drupal version
Drupal 4.5.x or older, Drupal 4.6.x, Drupal 4.7.x, Drupal 5.x
Audience
Themers

Theming Guide

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.