allow users to choose whether certain profile fields are visible or hidden

description

This handbook page explains how to allow your users to specify on their own account pages, which profile fields are visible or hidden when someone else is viewing their profile page.

example application

As an example, it might be useful if you are running a membership site where anonymous users can view profiles and you would like to offer the choice to members (registered users) whether their mobile phone number is visible to anonymous users or not.

usage

Step 1 of 2

Using the example of "Do you want to hide your mobile phone number from non-members?" follow these steps.

  1. Click through to ADMINISTER -> SETTINGS -> PROFILES
  2. Below the ADD NEW FIELD option, click on CHECKBOX
  3. Make the Form Name profile_hide_mobile
  4. Fill out the other fields to suit. (Tip: adjust the weight of this custom field so the checkbox appears just below the mobile phone number field on the user EDIT ACCOUNT page.)
  5. Save the field

Step 2 of 2

Use this snippet to show/hide the mobile phone number (where the fieldname for the mobile phone number is profile_mobile).

<?php if ($user->profile_mobile): /*check to see if the user has entered a mobile field. displays nothing if it is blank */ ?>
<?php if (($GLOBALS['user']->uid)  ||  (!$user->profile_hide_mobile) == '1') : /* check to see if the user viewing the page is logged in OR if the hide mobile field is selected */ ?>
<div class= "fields">
<P>Mobile phone number: <?php print ($user->profile_mobile) ;  /* display this users mobile phone number */?></p>
</div>
<?php endif ; /*end of show or hide check */?>
<?php endif ; /*end of snippet */?>

concise version of the same snippet without comments

<?php if (($user->profile_mobile) && (($GLOBALS['user']->uid)  ||  (!$user->profile_hide_mobile) == '1')) : ?>
<div class= "fields">
<P>Mobile phone number: <?php print ($user->profile_mobile) ;?></p>
</div>
<?php endif ; ?>

Notes

 
 

Drupal is a registered trademark of Dries Buytaert.