News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Displaying user's primary membergoup on a page

Started by Atomixx, January 05, 2019, 03:47:55 PM

Previous topic - Next topic

Atomixx

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?

vbgamer45

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

Arantor

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.

Atomixx

#3
Quote from: Arantor 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.

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

$context['member'] = &$memberContext[$memID];

Edit: Doesnt seem to work either. Any ideas?

xTyler

Which page is your form going to be on? Is it an action page or are you trying to use it outside of smf?

Atomixx

Quote from: xTyler 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?

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

xTyler

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.

Arantor

Quote from: Atomixx on January 05, 2019, 04:21:34 PM
Quote from: Arantor 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.

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

$context['member'] = &$memberContext[$memID];

Edit: Doesnt seem to work either. Any ideas?


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

Atomixx

Quote from: Arantor on January 05, 2019, 08:33:41 PM
Quote from: Atomixx on January 05, 2019, 04:21:34 PM
Quote from: Arantor 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.

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

$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



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

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

echo '

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


Arantor

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.

Advertisement: