Advertisement:
GCWebhosting

Author Topic: Displaying user's primary membergoup on a page  (Read 1142 times)

Offline Atomixx

  • Semi-Newbie
  • *
  • Posts: 29
Displaying user's primary membergoup on a page
« on: January 05, 2019, 03:47:55 PM »
Hello!

I am working with a form on my forum and I want some simple details to be autocompleted beforehand. These details are the date, forum username and the user's primary member group. I've been able to accomplish the date and username using $context['current_time'] and  $context['user']['name'] respectively. However, I've had trouble displaying the member group as it seems $context['member']['name'] does not work. I have not been able to find a way to define $context['member']. Is there an easier way I would go about this?

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,401
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Displaying user's primary membergoup on a page
« Reply #1 on: January 05, 2019, 03:50:20 PM »
Check $context['member']['group']


$groupName = (!empty($context['member']['group']) ? $context['member']['group'] : $context['member']['post_group']);
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Displaying user's primary membergoup on a page
« Reply #2 on: January 05, 2019, 04:02:33 PM »
That only works if $context['member'] is defined - which it frequently won't be (and isn't the case the OP mentions)

I think you can make it be defined with loadMemberData($user_info['id']); $context['member'] = loadMemberContext($user_info['id']); but my memory could be faulty.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Atomixx

  • Semi-Newbie
  • *
  • Posts: 29
Re: Displaying user's primary membergoup on a page
« Reply #3 on: January 05, 2019, 04:21:34 PM »
That only works if $context['member'] is defined - which it frequently won't be (and isn't the case the OP mentions)

I think you can make it be defined with loadMemberData($user_info['id']); $context['member'] = loadMemberContext($user_info['id']); but my memory could be faulty.

Yes defining $context['member'] is my problem as I see $context['member']['name'] does not work aswell. Still can't seem to make it work even with the code you supplied me. Looks like $context['member'] is defined in View-Profile.php as

Code: [Select]
$context['member'] = &$memberContext[$memID];
Edit: Doesnt seem to work either. Any ideas?
« Last Edit: January 05, 2019, 04:56:20 PM by Atomixx »

Offline xTyler

  • Semi-Newbie
  • *
  • Posts: 49
Re: Displaying user's primary membergoup on a page
« Reply #4 on: January 05, 2019, 05:23:26 PM »
Which page is your form going to be on? Is it an action page or are you trying to use it outside of smf?

Offline Atomixx

  • Semi-Newbie
  • *
  • Posts: 29
Re: Displaying user's primary membergoup on a page
« Reply #5 on: January 05, 2019, 05:28:44 PM »
Which page is your form going to be on? Is it an action page or are you trying to use it outside of smf?

I'm using Simple portal to create pages. This form will be on that page. So yes its on the forums

Offline xTyler

  • Semi-Newbie
  • *
  • Posts: 49
Re: Displaying user's primary membergoup on a page
« Reply #6 on: January 05, 2019, 05:38:27 PM »
The way I've done it on my forum is not the quickest and im sure there is a better route but I call $user_settings['id_group'] and then depending on the id work out the membergroup.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Displaying user's primary membergoup on a page
« Reply #7 on: January 05, 2019, 08:33:41 PM »
That only works if $context['member'] is defined - which it frequently won't be (and isn't the case the OP mentions)

I think you can make it be defined with loadMemberData($user_info['id']); $context['member'] = loadMemberContext($user_info['id']); but my memory could be faulty.

Yes defining $context['member'] is my problem as I see $context['member']['name'] does not work aswell. Still can't seem to make it work even with the code you supplied me. Looks like $context['member'] is defined in View-Profile.php as

Code: [Select]
$context['member'] = &$memberContext[$memID];
Edit: Doesnt seem to work either. Any ideas?


You need both the statements I had, not just the second one.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Atomixx

  • Semi-Newbie
  • *
  • Posts: 29
Re: Displaying user's primary membergoup on a page
« Reply #8 on: January 06, 2019, 09:36:22 PM »
That only works if $context['member'] is defined - which it frequently won't be (and isn't the case the OP mentions)

I think you can make it be defined with loadMemberData($user_info['id']); $context['member'] = loadMemberContext($user_info['id']); but my memory could be faulty.

Yes defining $context['member'] is my problem as I see $context['member']['name'] does not work aswell. Still can't seem to make it work even with the code you supplied me. Looks like $context['member'] is defined in View-Profile.php as

Code: [Select]
$context['member'] = &$memberContext[$memID];
Edit: Doesnt seem to work either. Any ideas?


You need both the statements I had, not just the second one.


Yes I used both. My code is below

Code: [Select]

global $context, $txt, $user_info, $user_profile;

loadMemberData($user_info['id']);
$context['member'] = loadMemberContext($user_info['id']);

echo '

<a>', $context['member']['group'], '</a>';

Offline Atomixx

  • Semi-Newbie
  • *
  • Posts: 29
Re: Displaying user's primary membergoup on a page
« Reply #9 on: January 12, 2019, 10:50:46 AM »
Bump?  :'(

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,252
    • StoryBB/StoryBB on GitHub
Re: Displaying user's primary membergoup on a page
« Reply #10 on: January 12, 2019, 12:26:47 PM »
What if you instead do var_dump($context['member']); instead of your echo? It won't show the correct output but it will show what ended up in the $context variable.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.