I'm trying to find some way to access (via php) a customized a user profile question within a page so I can customize content of the page based on their answer. For example, on one page I want to have 6 links visible to everyone, and a 7th link only visible to users who answer my profile question a certain way. So node access won't work. I also want instant access so relying on cron (like optin module) won't work either.

I did something similar by calling up $user, determining the role, and then customizing the page content based on that, but the custom profile questions don't seem to be accessible through the $user variable.

In drupal chat someone pointed me to the drupal function profile_load_profile (http://drupaldocs.org/api/4.5/function/profile_load_profile) but it looks like gibberish to me. I just need to be able to get the user's answer to my question (profile_affiliation | a pulldown list) into an "if" statement and I should be all right from there.

Thanks for any help you can give. I am really impressed with Drupal, but I was just about to give up on it because of a half dozen hurdles I didn't know enough code to work my way through. With the answer to this I think I'll be homefree! (for now). There's light at the end of the tunnel!

Caveman

Comments

nevets’s picture

Here is a small sample of using profile_load_profile

<?php
your_function()
{
  global $user;

  profile_load_profile($user);
  // Now $user has the profile fields
  if ( $user->profile_yourfieldname )
  {
    // Do something
  }
}
?>
caveman’s picture

I really appreciate your help, nevets! It worked perfectly for me. I'm using it extensively on my site and it is powerful. Now when a person registers and gives their affiliation, their entire browsing experience is shaped and defined by that--including both blocks and pages. I'm ecstatic!

Caveman

PS. Sorry about posting in two different threads. Didn't discover the other until I posted my own question, despite quite a bit of searching. Found googling works better.

functions’s picture

Hi everyone, I'm new to drupal (and very excited!) I was looking to achieve something similar to this, where a user would be automatically assigned a role based on a registration answer they provide (perhaps from a dropdown menu.) From this thread, it looks like this is possible. I'd be very grateful if anyone could lead me in the right direction. Thank you!

Mr Maggoo’s picture

I want to have a custom profile field that is profile_msn

when someone views this user's page i.e. goes to 'http://mysite.com/user/1' they can see the person's msn address, and then a custom peice of code that displays wether or not that person's status is 'Online' on their MSN account.

Even better, can I display the online/offline status image on the 'who's online' block?

Thanks

Miles

fletcherson’s picture

Could someone provide me with an example of how the code would have to be if I want to see the online status of "someone" in MSN-messenger?

Where exactly would I have to put the MSN/Yahoo-ID?

theamoeba’s picture

damn thank you, i was beginning to despair. it works beautifully.

--
theamoeba
www.amoebasys.com
www.espresso-online.info (blog)

jazzitup’s picture

That was keeping me busy for a while until I've found this post...