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 a user friendly "this user has not provided their [profile field]" text when a profile field is not filled out. An alternative to simply ignoring the field. I find it useful for mobile phone numebrs or personal contact details, e.g. "please contact this user by private message for their [profile field]".

The default settings with Drupal is to hide or ignore empty fields, so Users sometimes don't know they can add a field unless they look at the various EDIT MY ACCOUNT options.

Dependencies: profile.module

Usage

  • For use in your user profile page override
  • Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
  • Change the $pfieldname value in the first line to match the profile field name name you are referecing.
  • If you are using this snippet more than once in the same user_profile.tpl.php file add a number to the end of the $pfieldname titles each time you copy and use the snippet. e.g. $pfieldname1, $pfieldname2, $pfieldname3 etc.
  • Tested and works with Drupal 4.5 and 4.6
  • Change the div class names or the link prefix text to suit.
<?php $pfieldname = "profile_mobile_no"; ?> 
<?php if(($user->$pfieldname) == ""): ?>
<div class="fields">
Please contact me by private message from my mobile phone number.
</div>
<?php endif; ?>
<?php print $user->$pfieldname ; ?>
<div class="fields">
</div>

Comments

volocuga’s picture

This works for me in drupal 6.14

<?php $pfieldname = "profile_user_name"; ?>
<?php if(($account->$pfieldname) == ""): ?>
<?php print t('No info yet'); ?>
<?php else : ?>
<?php print $account->$pfieldname ; ?>
<?php endif; ?>
azwildcat’s picture

I tried your solution but how do I retain the existing labels. When a user does not fill out a field, on his profile page, the message displays but the label associated with the field is missing. Moreover, the profile category title, i.e., something like “Personal Information” is missing as well. The presentation should be consistent even if users do not choose to enter information in certain fields.