Hi

How can I have my users e-mail adresses to be shown in their profile?
I am trying to customize with some additional fields, but the e-mail adress is already submittet once in the registration, so it would look really stupid to have them fill that out twice.

Best regards

Jacob

Comments

Jacobtv’s picture

Really? No one has a solution?

Jacobtv’s picture

bump

mak1084’s picture

hey you have to use some modules like views and usernode to show it on the profile or user list if that does not solves then use. bio module or something nodeprofile module and use views to show up.

Jacobtv’s picture

I'm not sure how to do that. I am using Drupal 6.x, and all users, as a default, have a profilenode, that displayes all information entered regarding their profiles... Except the e-mail adress. If there was a way to edit this page, or replace it with a node created in views, that too is welcome.

Jacobtv’s picture

bump...

Jacobtv’s picture

...at all?

Jacobtv’s picture

Bump

-Anti-’s picture

It occurs to me that having an profile email which is completely separate from the
registration email is a very good thing:

1)
In Drupal, the registration email is NEVER shared or seen by other users.
Users don't even have a choice of whether to share it or not.
It is a great feature that registration emails cannot be accidentally shared.

2)
The registration email is required, whereas a profile email address should be a choice.

3)
Users have more flexibility - they can use the same email or two different addresses.
I often use disposible addresses and forwarding on websites & forums for spam control purposes.

4)
People are used to duplicating their email address anyway, because most sign-up forms require it twice for error checking purposes; most people know how to copy/paste their address from one field to another.

IMO, having to type it twice (or leave the field blank) isn't stupid at all.
Have you really thought about the consequences of forcing users to reveal their registration email?

Just something to mull over!
Cheers

Jacobtv’s picture

I have thought it over. The access to the profiles will be restricted from the administrators side, so only users with a certain role can view it.

I can see your point, but for my purpose I need the e-mail address to be displayed in the profile field. So again if anyone has a way to do this it would be great:-)

Jacobtv’s picture

Bump

steevithak’s picture

One of our customers has requested that we modify their drupal website to display the email address on the profiles. So I could really use a solution to this one too. Anyone have a suggestion?

Unless someone knows an easier way, I'm assuming I can make a new template in the theme for the profile page, then add some php code to grab the email and render it on the page. Would that work?

steevithak’s picture

Ok, I've made a template to replaced the default user profile. Based on what I'd read elsewhere on this site, it appeared displaying the user email would be as simple as printing user->mail -- however, this displays the email of the currently logged in user, NOT the user whose profile is being viewed. Oops. So how do I get the email or uid of the user whose profile is being displayed? It doesn't seem to be included in the $profile or $user_profile variables available in the user-profile.tpl.php. Any ideas?

WorldFallz’s picture

it should be something like:

<?php
$profile_user = user_load(array('uid' => arg(1)));
?>

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

steevithak’s picture

Thanks! That did it. The total solution then is to:

1. copy the default profile template into your theme directory (the default template I copied is /modules/user/user-profile.tpl.php)

2. just after the initial <div class="profile"> insert this code:

 $profile_user = user_load(array('uid' => arg(1)));
 if($profile_user) {
   print '<h3>Contact Information</h3>';
   print '<dl><dt class="profile-profile_email">Email</dt>';
   print '<dd class="profile-profile_email"><a href="mailto:' . $profile_user->mail . '">' . $profile_user->mail . '</a></dd></dl>';
 }

3. That's it, all your profiles should have email addresses. The spammer's email harvesting robots should be hitting your page any minute now. :)

Rosamunda’s picture

This snippet shows the logged in user´s email, not the node´s author...
Thanks!

Rosamunda
Buenos Aires | Argentina
www.ligadelconsorcista.org

alienresident’s picture

I know this is a bit late to help you but it might help others.

If you change user_load to node_load and call it form the node.tp.php that should do it.
Also you may want to obfuscate your email using a php function in your template.php
See http://www.givegoodweb.com/post/67/php-email-obfuscate for details

davidbessler’s picture

Thanks for this. Our entire site is off limits to the public, so it shouldn't be a problem to list email addresses on the profiles. Is this true? If not, then we have a problem because we have MUCH more sensitive information on the site than people's email addresses. Correct me if I'm wrong ... seriously.

zrednaz’s picture

The code posted by steevithak works like a charm.

However, I would add this:
After step 1, clear your cache (Configuration --> Performance) or Drupal won't discover your custom user profile template.

The following line is obsolete in D7. It works, but it displays warnings:
$profile_user = user_load(array('uid' => arg(1)));

Use this instead:
$profile_user = user_load(arg(1));

gumol’s picture

The way I did it, imho the best one, with weight parameter, which displays it on the top of the list.

function my_module_user($op, &$edit, &$account, $category = NULL) {
global $user;
if ($op == 'view'){
    	$account->content['e-mail'] = array(
          '#type' => 'user_profile_category',
          '#title' => t('User e-mail adress'),
          '#weight' => -9,
        );
		$account->content['e-mail']['e-mail'] = array(
            '#type' => 'user_profile_item',
            '#title' => t('E-mail'),
            '#value' => $user->mail,
          );
    }
}
TWD’s picture

thanks.

dahousecat’s picture

I found this method works well for me in D7...

function hook_user_view($account, $view_mode, $langcode) {
	$account->content['field_email'] = array(
		'#theme' => 'field',
		'#weight' => 1,
		'#field_type' => 'text',
		'#label_display' => 'inline',
		'#field_name' => 'email',
		'#bundle' => 'user',
		'#title' => t('E-mail'),
		'#items' => array(array('value'=>$account->mail)),
		0 => array('#markup' => $account->mail),
	);
}
Jaypan’s picture

You should only do this if anonymous users don't have permission to view profiles. Otherwise they are going to get spammed endlessly when the bots harvest their email addresses from your site.

drummondf’s picture

Agreed - there is no situation where this information should be compromised so carelessly.

Direct users to the contact form instead, a la Drupal.org :)

Ask me about marketing

Sata’s picture


/** Implements hook_user_view()
 * 
 */
function profile2_account_email_user_view($account, $view_mode, $langcode) {
  $account->content['profile_' . 'main']['view']['profile2'][]['field_email'] = array(
    '#theme' => 'field',
    '#weight' => 1,
    '#field_type' => 'text',
    '#label_display' => 'inline',
    '#field_name' => 'field_email',
    '#entity_type' => 'profile2',
    '#bundle' => 'main',
    '#title' => t('Email'),
    '#items' => array(array('value'=>$account->mail)),
    0 => array('#markup' => l($account->mail, 'mailto:'.$account->mail)),
  );
}