Handling freeform profile fields

Last modified: August 27, 2009 - 00:30

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 custom User Profile Freeform Fields. If the user has not specified anything, it displays nothing.

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 custom profile freeform field name by changing the $fieldname value in the first line of the snippet to suit. (Tip: go to administer -->> settings -->> profile and in the second column it will give you the field name.)
  • Make sure to enter a "Page title" for the custom profile freeform field. If you don't, the links won't work.
  • Tested and works with Drupal 4.5 and 4.6
  • Change the div class names or the prefix text to suit.
  • If you are using the same snippet more than once in the same user_profile.tpl.php file add and increment a number to the end of the of the $fieldname tag e.g. $fieldname2, $fieldname3 etc. each time you copy and use the snippet.

<?php $fieldname = 'profile_keywords'; ?>
<?php if($account->$fieldname != ""): ?>
<div class="fields">
<p><b>Keywords:</b></p>
<ul>
<?php
  $values
= split("[,\n\r]", $account->$fieldname);
 
$fields = array();
  foreach (
$values as $value) {
    if (
$value = trim($value)) { ?>

      <li><?php print l($value, 'profile/'. $fieldname .'/'. $value, array('title' => 'Users who share this keyword')); ?></li>
    <?php }
  }
?>

</ul>
</div>
<?php endif ?>

Drupal 5?

bboyjay - February 23, 2007 - 18:59

I have it working for Drupal 5, but again, the assumption that clean URL's makes things difficult.

<?php $fieldname = 'profile_keywords'; ?>
<?php if($user->$fieldname != ""): ?>
<div class="fields">
  <p><b>Keywords:</b></p>
  <ul>
  <?php
    $temp_array
= split("[\n,]", $user->$fieldname);
   
$count_total = count($temp_array);
    for(
$counter=0; $counter<$count_total; $counter++):?>

      <?php $link = each($temp_array) ?>
        <li><?php print l($link[value], 'profile/'.$fieldname.'/'.preg_replace('[\s]', '+', trim($link[value]))) ?></li>
      <?php endfor ?>
  </ul>
</div>
<?php endif ?>

If you don't have clean URL's enabled, the '+' elements (substitutes for spaces) changed to a URL friendly equivalents.

Anyone else have any ideas?

does't work on my site (drupal 5.7)

Glowingtree - March 4, 2008 - 21:16

I made 2 different test users that have the same keywords, the keywords come up as links but when clicked they go to a "page cannot be displayed" page. I have clean urls working btw

Anyone have a snippet for

Fayna - February 11, 2009 - 00:43

Anyone have a snippet for Drupal 6?

 
 

Drupal is a registered trademark of Dries Buytaert.