MyBB Community Forums

Full Version: How to show Custom Profile Fields in areas other than "Additional Information"?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I did tell you that it doesn't work with dropdown fields. You will need to look at the PHP to figure out which variable you can call to pull out the individual field.

Here's what you can do instead. I tested this in 1.8, but it should also work in 1.6.

Find in Usercp.php around line 717

if($customfields)
	{
		eval("\$customfields = \"".$templates->get("usercp_profile_profilefields")."\";");
	}

Right above that, add this:

$custom_fields = explode("end: usercp_profile_customfield",$customfields);

In your templates, you can now call {$custom_fields[X]} where X is the array number. To find out what that it is (It is different from the FID number), you can add this line below the one I just gave you:

print_r($custom_fields);

Because of how myBB comments its code, to see the numbers you'll need, you want to view the source of the page. Look for lines that look like this: [0] => <!-- start: usercp_profile_customfield --> The [0] is the number that you want. To call the first field, you'll use:

{$custom_fields[0]}

This will echo out all of the necessary HTML for the field. By default, myBB puts each custom profile field in its own table row. If you want to change that, just edit the usercp_profile_customfield HTML. You can then use the above variable wherever you'd like in the usercp_profile template.

This method will allow you to easily access the dropdowns as well.

Edit: Hmm, using the \n as the delimiter for the explode function causes some issues with textareas that I hadn't noticed before, so the idea itself works, I just need to do some testing to get the right delimiter for you.

Edit: Updated with a better delimiter that should work just fine.
Wow. Thank you very much. I learned about arrays, multi dimensional arrays, but I would have never thought about doing it that way. You're very smart indeed.

Is there a way to make it html valid (XHTML 1.0 Transitional)?
Well, there's nothing in the code I provided that would make it invalid, so that would depend on what you do with it.

On another note, I see that you upped your request to $40, shall I PM you my paypal account? Smile
The commenting <!-- --> makes it invalid, as well as the other <td><tr> and other elements.

When I try inserting it anywhere in the template "usercp_profile", it makes the page invalid. Even when I insert it just below {$customfields}, it's invalid.

Sure, if you can solve these problems, I won't mind paying you via PayPal.
For the <td></tr> elements, you're going to have to change the HTML in usercp_profile_customfield to either get rid of those table elements or you have to include {$custom_field[0]} in a table. Fixing that depends entirely on what you want to do with it.

I'm testing this locally, so I can't test the validation, but you can try seeing if changing the delimiter to:
<!-- end: usercp_profile_customfield -->

That should remove that particular comment out completely.
(2014-12-04, 03:39 AM)jshort Wrote: [ -> ]For the <td></tr> elements, you're going to have to change the HTML in usercp_profile_customfield to either get rid of those table elements or you have to include {$custom_field[0]} in a table. Fixing that depends entirely on what you want to do with it.

I'm testing this locally, so I can't test the validation, but you can try seeing if changing the delimiter to:
<!-- end: usercp_profile_customfield -->

That should remove that particular comment out completely.

The new delimiter you gave solves the XHTML Validation issue. It now validates.

I removed all table elements in usercp_profile_customfield, because putting $custom_fields[0] in a table created more validation problems because there are tr's, td's and tables everywhere, in the wrong places.

Now the only problem is that the "bio:" text isn't at the top left hand side of the textarea, because it isn't in a table (and I don't know how to vertically align text if it isn't in a table). The "bio:" text is right at the bottom of the text area.

That's because now my usercp_profile_customfield template only consists of

{$profilefield['name']}:
{$code}

So it outputs bio: at the bottom left hand side of the massive bio textarea box.

EDIT: I solved it. I just put a <div style="float: left;"> around {$profilefield['name']}: </div>

Thanks for your help. If you want some munnies, PM me your PayPal email.
Pages: 1 2