News:

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

Main Menu

Custom fields in memberlist?

Started by palbanes, April 21, 2008, 07:45:34 PM

Previous topic - Next topic

palbanes

I apologize if this has been covered before but I couldn't find anything in my search efforts.

I have created a new custom field called NTRP ( a selection list with 2.5,3.0,3.5,4.0,4.5+ as options) and I would like two things:

1.  To be able to display this in memberlist and be able to sort by it
2.  Be able to search for members by NTRP

Is this possible?

Thanks in advance,
-Phil

Kindred

it is possible, but will require you to recode/modify the memberlist.php and memberlist.template.php
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

palbanes

Quote from: Kindred on April 21, 2008, 08:00:26 PM
it is possible, but will require you to recode/modify the memberlist.php and memberlist.template.php

Could you give me an idea of which sections to modify?

palbanes

ahh.. the custom fields are not stored in the member table... they have their own table

palbanes

now i'm really confused.. if smf_custom_fields table contains the fields, where is the relationship to the member?

Kindred

??? smf_custom_fields? ???

custom fields are stored in the smf_themes table
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

palbanes

#6


ahh.. the actual user-selected data is stored in smf_themes.. that brings up another question... since the value is assigned to a user's member id, how can I integrate this into the memberlist?

Kindred

with database queries or use a database query to add it to the user_info array



However, it looks like custom-fields is queried to be set up in the memberlist anyway...  at least for search (// Can they search custom fields?)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

palbanes

Quote from: Kindred on April 21, 2008, 11:34:20 PM
with database queries or use a database query to add it to the user_info array



However, it looks like custom-fields is queried to be set up in the memberlist anyway...  at least for search (// Can they search custom fields?)

how so? is this dependent on theme?

Kindred

search is not dependent on theme

The search routine in memberlist.php will search the custom fields for the search string, assuming they are searchable
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

rsw686

Text and Large Text fields can already be searched on the memberlist. However you would think that if you can search them they would be displayed on the memberlist. Reguardless since the core functionality is there it shouldn't be hard to extend to the other fields.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

palbanes

Quote from: rsw686 on April 22, 2008, 09:11:37 AM
Text and Large Text fields can already be searched on the memberlist. However you would think that if you can search them they would be displayed on the memberlist. Reguardless since the core functionality is there it shouldn't be hard to extend to the other fields.

how is it possible to search for them?  I'm relatively new to PHP and I'm not sure how I would add a checkbox for my custom field to the member search

rsw686

In the Profile Fields admin section you can check a box for Text and Large text to be searchable in the field properties.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

palbanes

Quote from: rsw686 on April 22, 2008, 09:20:44 AM
In the Profile Fields admin section you can check a box for Text and Large text to be searchable in the field properties.

ahh... im using a list so I guess I'm out of luck

rsw686

You can change the can_search field in the database for that field to 1. Then in Memberlist.php find


// Can they search custom fields?
$request = $smcFunc['db_query']('', '
SELECT col_name, field_name, field_desc
FROM {db_prefix}custom_fields
WHERE active = {int:active}
' . (allowedTo('admin_forum') ? '' : ' AND private != {int:private}') . '
AND can_search = {int:can_search}
AND (field_type = {string:field_type_text} OR field_type = {string:field_type_textarea})',
array(
'active' => 1,
'can_search' => 1,
'private' => 2,
'field_type_text' => 'text',
'field_type_textarea' => 'textarea',
)
);


and replace with


// Can they search custom fields?
$request = $smcFunc['db_query']('', '
SELECT col_name, field_name, field_desc
FROM {db_prefix}custom_fields
WHERE active = {int:active}
' . (allowedTo('admin_forum') ? '' : ' AND private != {int:private}') . '
AND can_search = {int:can_search}',
array(
'active' => 1,
'can_search' => 1,
'private' => 2,
)
);


Now you can search that field. Granted it would be good to modify the profile field's admin page to show the can_search checkbox for all fields. However by changing the database value manually you can get around that. Chances are your not going to change the field properties that much anyway.

The only piece your missing is displaying the field choice on the memberlist.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

palbanes

thank rsw, I'll give that a try tonight!

palbanes

you guys have been very helpful.. one last thing, if I wanted to replace the ICQ column in member list the with the 3 digit NTRP custom field I've made, what would I need to change?

Kindred

you would need to change code in memberlist.template.php.

You would also have to draw the value of your custom field out of the database and into a useable variable/array.


Actually, IMO, the custom fields should be added in a "customfield" subset of the user_info array
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

palbanes

Quote from: Kindred on April 22, 2008, 11:11:58 AM
you would need to change code in memberlist.template.php.

You would also have to draw the value of your custom field out of the database and into a useable variable/array.


Actually, IMO, the custom fields should be added in a "customfield" subset of the user_info array

sounds like it could be over my head.. I might have to just stick with the ability to search (which works now, thanks guys)

metallica48423

Were you ever able to resolve this?

There was actually another suggestion made on this not long ago where one of the developers thought it might be a good

Currently though i can't see an easy way to add custom fields to the list without decent modifications to the Memberlist.php file.

You can see where it was added to the bugtracker as a feature request. Bug #2110: Show Custom Profile Fields on Memberlist
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Advertisement: