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?
Check $context['member']['group']
$groupName = (!empty($context['member']['group']) ? $context['member']['group'] : $context['member']['post_group']);
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.
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?
Which page is your form going to be on? Is it an action page or are you trying to use it outside of smf?
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
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.
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.
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>';
Bump? :'(
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.