Username Vs User ID on memberlist_view/profile

Discussion forum for MOD Writers regarding MOD Development.
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

Hi folks

We've got a modified version of the user profile form, from which we've got a button to link to an extra profile page, which itself holds a number of Custom Profile fields

The button link is done via

Code: Select all

href="memberlist.php?mode=testprofile&un={USERNAME}"
This works a treat, except when there's a user with a name such as "Tom & Jerry", as the ampersand messes up the URL.

I've tried swapping &un={USERNAME} with &u={USER} but this just takes the user to their own custom profile page! I assume that there must be a way to find the user ID of the member whose page you are viewing?

I've been searching around the forum here for the last couple of hours and can't find a solution, so if any kind soul could offer some advice, I'd be very grateful! :mrgreen:
www.natterzone.com / www.natterzone.net - a friendly place to chat!
Bruce Banner
Registered User
Posts: 1338
Joined: Thu Sep 25, 2014 10:36 am

Re: Username Vs User ID on memberlist_view/profile

Post by Bruce Banner »

There's just been a reply to this, but I can't see it.
Bruce Banner
Registered User
Posts: 1338
Joined: Thu Sep 25, 2014 10:36 am

Re: Username Vs User ID on memberlist_view/profile

Post by Bruce Banner »

Bruce Banner wrote:There's just been a reply to this, but I can't see it.
EDIT: Sorry, ignore me, I'm asleep. I thought I'd started this thread and Cedric had replied to it. Sorry.
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

:) If you have a similar issue and an answer, I'd be interested to know how it worked out!
www.natterzone.com / www.natterzone.net - a friendly place to chat!
Bruce Banner
Registered User
Posts: 1338
Joined: Thu Sep 25, 2014 10:36 am

Re: Username Vs User ID on memberlist_view/profile

Post by Bruce Banner »

cedricthecat wrote::) If you have a similar issue and an answer, I'd be interested to know how it worked out!
Nah. Sorry. I'd just woken from a nap on the couch and my mind was all fuzzy. Wasn't even looking at what the thread was about; just wasn't thinking clearly.
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

Darn, I was getting all excited!

Anyone?!
www.natterzone.com / www.natterzone.net - a friendly place to chat!
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

In the hope that some might be reading this and may have some sage advice, would it be possible to use something along the lines of

Code: Select all

<!-- IF ($user->data['user_id'] == 921) -->
<dd><a href="memberlist.php?mode=testprofile&un=Tom %26 Jerry" class = "button1" " title="Click here to see the extra profile for {USERNAME}">Go to Extra Profile</a>
<!-- ELSE -->
where 921 is the user ID for the ampersandy user name?

The above works when the user is accessing the page themselves, but not sure how to reference the ID for when other users are viewing Tom & Jerry's page......
www.natterzone.com / www.natterzone.net - a friendly place to chat!
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Username Vs User ID on memberlist_view/profile

Post by RMcGirr83 »

You should be using username_clean from the database instead of username
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

RMcGirr83 wrote:You should be using username_clean from the database instead of username
I'm sure I should, but unfortunately it doesn't work at all with username_clean! :(
www.natterzone.com / www.natterzone.net - a friendly place to chat!
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Username Vs User ID on memberlist_view/profile

Post by RMcGirr83 »

How is this {USERNAME} being populated? Why aren't you using the user id instead?
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

Hi Rich

In memberlist_view, we're using

Code: Select all

<a href="memberlist.php?mode=testprofile&un={USERNAME}" class = "button1" onmouseover="mOver3(this)" onmouseout="mOut3(this)" title="Click here to see the car profile for {USERNAME}">Go to Car Profile</a>
to get to the extra profile page

Apologies as to the fact that I can't remember exactly why I set it up like this, as this is something I started a year ago and have recently returned to! :oops:

I seem to recall that using the equivalent of testprofile&u={USER} would not work. Certainly, if I try changing to this it just reports "user not found", as when hovered over it doesn't append an ID number after the u=

We've also got a link under the avatar in viewtopic_body to go directly to the extra profile page, and this does work

Code: Select all

<a href="memberlist.php?mode=testprofile&{postrow.U_POST_AUTHOR}" <span style="color: #800000;" title="Click here to see car details for {postrow.POST_AUTHOR}">{postrow.POST_AUTHOR}'s car details</a>
not sure entirely why though!

Interestingly, when hovered over this link displays

/memberlist.php?mode=testprofile&./memberlist.php?mode=viewprofile&u=387

(with 387 being the user_id of the member being tested)

TBH, this is starting to drive me a bit nuts, and I'm having trouble even trying to explain it all, so apologies for this too!

If I try
www.natterzone.com / www.natterzone.net - a friendly place to chat!
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Username Vs User ID on memberlist_view/profile

Post by RMcGirr83 »

The question was how are you setting this {USERNAME} as that isn't set within memberlist.php file in the template variables. You should also be using append_sid for your link.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

I've got it in my memberlist.php

Code: Select all

// Grab data
$username	= request_var('un', '', true);
with a fair number of other occurrences of $username, enough in fact to make me think that surely I can't have added them all, although I do admit the memberlist.php has quite a lot of alterations!

TBH, although I do relish a challenge and would like to get to the root of how to solve this puzzle, it's taking too much of my brain up at the moment, and it's not fair to expect help when I can't supply concise answers.

I've checked and we actually only have one member with a name with an ampersand within it. Interestingly, if it's got the ampersand and no spaces, it works fine (so as an example Tom&Jerry as opposed to Tom & Jerry) so I think I'll either just ignore it, or maybe ask that user if they are OK losing the spaces!
www.natterzone.com / www.natterzone.net - a friendly place to chat!
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Username Vs User ID on memberlist_view/profile

Post by RMcGirr83 »

Code: Select all

$username   = request_var('un', '', true);
is a PHP variable you are calling a template variable so how is the template variable being set?
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
cedricthecat
Registered User
Posts: 259
Joined: Sun May 03, 2009 4:02 pm
Name: Dave

Re: Username Vs User ID on memberlist_view/profile

Post by cedricthecat »

Hi RIch,

Thanks for getting back on this
RMcGirr83 wrote:

Code: Select all

$username   = request_var('un', '', true);
is a PHP variable you are calling a template variable so how is the template variable being set?
In all honesty, I can't remember! :oops:

I've come up with a workaround now though, as it turns out that only one of our three users with an ampersand in their name is affected (I know I really should try to get to the bottom of it.....)

What I've done is popped this into memberlist.php

Code: Select all

$template->assign_var('AND_NAME, "Tom & Jerry");
and this into the viewprofile page, linking to the custom page

Code: Select all

<!-- IF USERNAME == AND_NAME -->
<a href="memberlist.php?mode=testprofile&un=Tom %26 Jerry" class = "button1"  title="Click here to see the extra profile for {USERNAME}">Go to Extra Profile</a>
<!-- ELSE -->
<dd><a href="memberlist.php?mode=testprofile&un={USERNAME}" class = "button1"  title="Click here to see the extra profile for {USERNAME}">Go to Extra Profile</a>
<!-- ENDIF -->
Undoubtedly messy but it works - just need to make sure I don't let any more "&" names through! (oh and also I need to go back and address the append_sid issues!)
www.natterzone.com / www.natterzone.net - a friendly place to chat!
Locked

Return to “[3.0.x] MOD Writers Discussion”