MyBB Community Forums

Full Version: Separating Custom Fields into Sections
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Right now the UserCP just grabs all the custom fields and spits them out in table rows for user selection/answering. I'd like to be able to break them up into sections/categories instead of just one long string (I have several hundred).

I've had a look at this thread and while I could manually copy each one, it also doesn't address the 'selected' tag on the input.

Would it be possible to easily create arrays of custom fields? Either with a new 'category' column in the customfields table or with multiple queries with a WHERE limiter? Then loop the arrays through the existing templates? Or a better way?

Currently:

--Custom Fields--
Field 1
Field 2 
Field 3

Desired:

--Customfields--
---Category A---
Field 1
---Category B---
Field 2
---Category C---
Field 3

It's really just a visual aesthetic/ease of use (500+ fields) where I could ideally put the categories of fields in collapsible sections, so it's not a huge deal if it's not easily doable.
(2019-02-21, 02:52 AM)Ersatz Haderach Wrote: [ -> ]Right now the UserCP just grabs all the custom fields and spits them out in table rows for user selection/answering. I'd like to be able to break them up into sections/categories instead of just one long string (I have several hundred).

I've had a look at this thread and while I could manually copy each one, it also doesn't address the 'selected' tag on the input.

Would it be possible to easily create arrays of custom fields? Either with a new 'category' column in the customfields table or with multiple queries with a WHERE limiter? Then loop the arrays through the existing templates? Or a better way?

Currently:

--Custom Fields--
Field 1
Field 2 
Field 3

Desired:

--Customfields--
---Category A---
Field 1
---Category B---
Field 2
---Category C---
Field 3

It's really just a visual aesthetic/ease of use (500+ fields) where I could ideally put the categories of fields in collapsible sections, so it's not a huge deal if it's not easily doable.

Look at this screenshot. Is this what you are looking for?

[Image: bda960ab4576c5dd347f34bd52e61dad.png]
Uh??? No. I'm talking about custom profile fields.
(2019-02-21, 07:28 AM)Ersatz Haderach Wrote: [ -> ]Uh??? No. I'm talking about custom profile fields.

Your first post was not clear on this.
(2019-02-21, 06:54 PM)Serpius Wrote: [ -> ]
(2019-02-21, 07:28 AM)Ersatz Haderach Wrote: [ -> ]Uh??? No. I'm talking about custom profile fields.

Your first post was not clear on this.

It was perfectly clear unless:
-- you think that "custom fields" mean "forums" 
-- you also think that forums appear in the User CP
-- you also didn't bother to read the thread I linked

You read it sloppy. Just like you read this thread sloppy. Own it, don't put it on me.
I need something similar
I've been digging and digging and this was the most complete answer (as already noted without having current values populated) with 2 or 3 other exact same questions being posed without any replies.

So... I solved it myself.

Before usercp.php loops the fields through the templates to create that awful single string, it puts them in the $pfcache array (line 483). Inspecting $pfcache with print_r shows that all the profile field variables are there except for the actual values -- but those are in the $user array.

The $pfcache[fid] consists of:
Array (
[fid] =>
[name] =>
[description] =>
[disporder] =>
[type] =>
[regex] =>
[length] => 0
[maxlength] => 0
[required] =>
[registration] =>
[profile] => 0
[postbit] => 0
[viewableby] =>
[editableby] =>
[postnum] =>
[allowhtml] =>
[allowmycode] =>
[allowsmilies] =>
[allowimgcode] =>
[allowvideocode] =>
)

To create a new section, you can copy the usercp_profile_customfield template and appropriate usercp_profile_profilefields_inputtype templates to create your own:

<tr>
<td>
 <div class="customfieldname" ><span>{$pfcache[1]['name']}</span></div>
 <div class="customfielddescription" ><span class="smalltext">{$pfcache[1]['description']}</span></div>
</td>
</tr>
<tr class="customfieldoptions" >
<td>
 <input type="{$pfcache[1]['type']}" name="profile_fields[fid{$pfcache[1]['fid']}]" class="textbox" size="{$pfcache[1]['length']}"{$maxlength} value="{$user['fid1']}" />
</td>
</tr>

You can see where I plugged in the $pfcache with FID where needed and then used the $user array to populate the input with the current value.

Now, unless you do every single custom field by hand and delete {$customfields} from the usercp_profile_profilefields template, there are going to be duplicate entries. To address this, we need uscerp.php to skip over the fields that were hand-coded (this is unecessary if the custom field inputs are being coded into a different page than usercp.php).

Find in usercp.php (after backing up):
foreach($pfcache as $profilefield)
 {
Change to:

 $removedarrays = array(1,2,3...);
 
foreach($pfcache as $profilefield)
{

if (!in_array($profilefield['fid'],$removedarrays)) {

About 180 lines down, find:
$seloptions = array();

 }

Change to:
$seloptions = array();
 }
}

This wraps the whole $customfields in a condition where you can make it skip the fields you hand-coded, just by adding or removing them from the $removedarrays line.  Now you're free to display your custom field inputs however you like, wherever you like.

Note: You could probably splice the $pfcache into sections and duplicate the $customfields creation process for each so that you don't have to hand-code each one... but that was a lot more How-To than I was up for writing.
(2019-02-21, 07:13 PM)Ersatz Haderach Wrote: [ -> ]
(2019-02-21, 06:54 PM)Serpius Wrote: [ -> ]
(2019-02-21, 07:28 AM)Ersatz Haderach Wrote: [ -> ]Uh??? No. I'm talking about custom profile fields.

Your first post was not clear on this.

It was perfectly clear unless:
-- you think that "custom fields" mean "forums" 
-- you also think that forums appear in the User CP
-- you also didn't bother to read the thread I linked

You read it sloppy. Just like you read this thread sloppy. Own it, don't put it on me.

You want to put 500+ fields in the UserCP? 

Seriously? Why?

Do NOT berate me or others simply because we misunderstood you. There are better ways of correcting others.
Attributes / variables for characters in an RPG forum.

Do NOT accuse me of being unclear because you read badly.  There are better ways to accept that you stuck your foot in your mouth than to jump on me for your fault. Acting Internet-polite now doesn't change that you started it by putting the blame on me.

It's clear that you have nothing to contribute -- please excuse yourself from this thread.
Let's not start a fight in this thread.

@Ersatz, have you ever thought about using a separate page for profile information related to a game or whatever that information is for? I'd suggest doing that and having a link to that. This way you keep forum stuff with the forum profile and nonforum profile info on a separate page.
Pages: 1 2