Handling multi-line profile fields
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_biographyused 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 ?>