Adding custom profile field to memberlist

Discussion forum for MOD Writers regarding MOD Development.
HondaCop
Registered User
Posts: 20
Joined: Sat Apr 05, 2008 4:12 am

Re: Adding custom profile field to memberlist

Post by HondaCop »

My next question would be... How can I output the userid number?
nylander
Registered User
Posts: 14
Joined: Sat Apr 05, 2008 12:42 am

Re: Adding custom profile field to memberlist

Post by nylander »

:?: Perhaps I missed something here; I'm using 3.0.0, and have added several new fields to the profile. Some are required for registration, while others are not. In updating the member list page, the addition of the table header row works fine, but I do not seem to be able to see the data.

For example,

Code: Select all

		<td class="info"><!-- IF memberrow.PROFILE_COUNTRY_VALUE -->{memberrow.PROFILE_COUNTRY_VALUE}<!-- ELSE -->&nbsp;<!-- ENDIF --></td>
Is the correct naming convention memberrow.PROFILE_insert_field_name_here_VALUE, where insert_field_name_here is the field identification entered on the ACP "Custom profile fields" page?

Thanks!
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53543
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Adding custom profile field to memberlist

Post by Brf »

Yes.
Assuming you have "Display" set to "Yes" to that field's management screen. and you have custom fields enabled at the bottom of the Load Settings screen.
nylander
Registered User
Posts: 14
Joined: Sat Apr 05, 2008 12:42 am

Re: Adding custom profile field to memberlist

Post by nylander »

:P Thanks for the help to the newbie: I did have "display" set to "yes" for each field, but I did not have custom fields enabled on the Load Settings screen.

Thanks!
oakridge
Registered User
Posts: 26
Joined: Mon Mar 10, 2008 1:59 pm
Location: AU

Re: Adding custom profile field to memberlist

Post by oakridge »

I have set both the Display and Load options to Yes and Purged the Cache and still not seeing any data in the Members list. My new column with correct heading is displayed correctly.
In my case the members Full Name variable is simply "name". The code I have inserted to display this is:-

<td><!-- IF memberrow.PROFILE_pf_name_VALUE -->
{memberrow.PROFILE_pf_name_VALUE}
<!-- ELSE -->&nbsp;<!-- ENDIF --></td>

I have tried "memberrow.PROFILE_name_VALUE" as well as both options capitalized but still nothing.

Your advice will be very much appreciated. (phpBB version is 3.0.0)
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53543
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Adding custom profile field to memberlist

Post by Brf »

You should be using

Code: Select all

PROFILE_NAME_VALUE
oakridge
Registered User
Posts: 26
Joined: Mon Mar 10, 2008 1:59 pm
Location: AU

Re: Adding custom profile field to memberlist

Post by oakridge »

So simple. Now it's working. Many many thanks.

I'm certain that is the first code that I installed and when it didn't work I started with all of the other options.
Well, never mind, it's now working perfectly. :D
‹(•¿•)›
nols76
Registered User
Posts: 2
Joined: Fri Apr 25, 2008 11:16 pm

Re: Adding custom profile field to memberlist

Post by nols76 »

I use Forumotion and tried to do this mod but since they have no customer support nor flexibility I will be launching my own phpBB. So much better....
swardi
Registered User
Posts: 5
Joined: Mon Jun 30, 2008 7:35 pm

Re: Adding custom profile field to memberlist

Post by swardi »

Hi,

I also wanted to do exactly same thing. I wanted to put real name instead of username in member list page. I created a custome profile with the name full_name. I entered the code as mentioned in the previous message. But it is not working for me. It is not showing me the names. Any idea what is happening.

Thanks.
codejunkie
Registered User
Posts: 26
Joined: Sun Jul 06, 2008 5:29 am

Re: Adding custom profile field to memberlist

Post by codejunkie »

kincoyotes wrote:Hello,

Ok i did add the custom profile fields in the member list, but how can i "sort" them ?
To include sorting, I needed to expand on this explanation by brf. (Which is a very good explanation on how to add a column to your memberlist.)

First, you need to determine what your column name is going to be. So, I opened the common.php file, which is located in each of the installed language sub folders found in my /language folder. At the end of the file you should see

Code: Select all

));

?>
On the line just before the double parenthesis and semi-colon I added

Code: Select all

		'FNAME'			=> 'Full Name',
		'SORT_FNAME'					=> 'Full Name',
Adding these two lines allows your template to be language independent again.

Now, back to your memberlist_body.html file. Previously, brf suggested the column name to be

Code: Select all

<th>Full Name</th>
We can now change it to read as

Code: Select all

<th><a href="{U_SORT_FNAME}#memberlist">{L_FNAME}</a></th>
Somewhere in the system, the U_ and the L_ will be removed from the text and replaced with the similar names we specified in the common.php file earlier. This change will allow a link to be created for sorting. We still have more to do, though, to make the sorting work. Fortunately, we only need to modify one more file, memberlist.php, which is found in your root folder "/" of your installed phpbb forum.

Several places will need to be modified or added to. Starting at around line 900, I added

Code: Select all

		$sort_key_text['y'] = $user->lang['SORT_FNAME'];
		$sort_key_sql['y'] = 'fd.pf_fname';
The SORT_FNAME matches the previous edit to the common.php file. The pf_fname is a field name as found in the profile_fields_data table. The fd. is for a future abbreviation in a SQL statement.

Now, scroll down to about line 1309 and look for

Code: Select all

// Get us some users :D
After that line and depending on how many custom fields you wanted to add, you need to add some type of conditional statement. Since I only wanted to add one new field / column to my memberlist page, I chose an if statement.

Code: Select all

if(isset($sort_key_sql['y'])) {
			$sql = "SELECT u.user_id
			        FROM " . USERS_TABLE . " u
			        $sql_from
			        LEFT JOIN " . PROFILE_FIELDS_DATA_TABLE . " fd ON (u.user_id = fd.user_id)
			        WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
			        $sql_where
			        ORDER BY $order_by";
		} else {
You should notice the previously mentioned fd on the LEFT JOIN line above.

Now, you need to add a closing bracket "}" after the previous SQL statement at about line 1325 to complete the if statement.

Code: Select all

}
One more addition is needed to get your link to show up on the column for sorting. At around line 1470 or so I added

Code: Select all

'U_SORT_FNAME'		=> $sort_url . '&sk=y&sd=' . (($sort_key == 'y' && $sort_dir == 'a') ? 'd' : 'a'),
Do you remember the 'y' we added earlier? This is where it is assigned via the url.

I hope all of this helps someone. It wasn't too difficult, just a little time consuming with the trial and error. The back trace error trapping in phpbb was a big help during the sql testing. Also, remember to purge your cache often while testing.

Oh, one more thing. If you want to specify a different default sort column, go to line 61 of the memberlist.php and change that letter. The default is 'c', which is the join date of your members. I changed it to 'y' for my new column.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53543
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Adding custom profile field to memberlist

Post by Brf »

Cool.
There have been a lot of users asking for this.
kpence73
Registered User
Posts: 26
Joined: Thu Jul 17, 2008 8:58 pm

Re: Adding custom profile field to memberlist

Post by kpence73 »

Ok, I have recoded as described here and have one of my custom fields sortable, but the post only describes how to do this on one custom field. I have two that I need to sort. The only part of the code I can't seem to customize is this:

Code: Select all

if(isset($sort_key_sql['y'])) {
         $sql = "SELECT u.user_id
                 FROM " . USERS_TABLE . " u
                 $sql_from
                 LEFT JOIN " . PROFILE_FIELDS_DATA_TABLE . " pf ON (u.user_id = pf.user_id)
                 WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
                 $sql_where
                 ORDER BY $order_by";
       } else {
Codejunkie says he/she only had one field to sort so he used an "if" statement. I cannot figure out how to add another condition to the statement. I have tried elseif and looked at switch, but don't understand php code and have spent about 5 hours trying. I know that the ['y'] is unique to only one field and I compensated for that by added all of the other code corrections in twice, once for my first name field and another for my last name field. I assigned first name with an "x". But no matter what I do, clicking the sort link in either field always sorts whatever is "y". So I assume it goes back to the code I pasted above and not having another condition to sort for "x".

HELP
codejunkie wrote:
kincoyotes wrote:Hello,

Ok i did add the custom profile fields in the member list, but how can i "sort" them ?
To include sorting, I needed to expand on this explanation by brf. (Which is a very good explanation on how to add a column to your memberlist.)

First, you need to determine what your column name is going to be. So, I opened the common.php file, which is located in each of the installed language sub folders found in my /language folder. At the end of the file you should see

Code: Select all

));

?>
On the line just before the double parenthesis and semi-colon I added

Code: Select all

		'FNAME'			=> 'Full Name',
		'SORT_FNAME'					=> 'Full Name',
........
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53543
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Adding custom profile field to memberlist

Post by Brf »

try using

Code: Select all

} else if ( ) {
after your first custom sort.
kpence73
Registered User
Posts: 26
Joined: Thu Jul 17, 2008 8:58 pm

Re: Adding custom profile field to memberlist

Post by kpence73 »

That did not work, I had already tried that. Also isn't it "elseif" not "else if"? Everything I found online said "else if" would not compile and it had to be "elseif. Anyway.....

When I used an elseif statement, the second condition was igored. If I clicked the sort link on the memberlist for the column that the elseif statement was conditional for, it would sort the OTHER column based upon the if statement above it. I also tried "or if"...didn't work.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53543
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Adding custom profile field to memberlist

Post by Brf »

No
It is else if

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