XF 1.1 Custom User Fields in XenForo 1.1

One of the most requested features for XenForo 1.1 has been the ability to define custom fields for your users. Here's a first look at the user field system we've built.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
 
This mean that the 'XenForo_Model_IdentityService' has gone in 1.1?

In version 1.0.4 I had something more complex than a regular expression in the (php) "verifyAccountName" function.

So, where I have to upload the php file with the php function?
 
There is the option of using PHP Callback for custom user fields.

Check the Twitter entry for example.
 
The fields have also a php callback where you can set the name
 

Attachments

  • callbac.webp
    callbac.webp
    17.1 KB · Views: 76
Thanks, I had seen it. My question is that I don't know where to upload the php file, or what format it should have. Is like this?

PHP:
static public function verifyAccountName(&$accountName, &$error) {
   ...
}

PD: I need a example. Where is the twitter entry? I can't find it.
 
XenForo_Helper_UserField
PHP:
<?php

class XenForo_Helper_UserField
{
    public static function verifyFacebook(array $field, &$value, &$error)
    {
        if (preg_match('#^https?://www\.facebook\.com/(\#!/)?profile\.php\?id=(?P<id>\d+)#i', $value, $match))
        {
            $value = $match['id'];
        }
        else if (preg_match('#^https?://www\.facebook\.com/(\#!/)?(?P<id>[a-z0-9\.]+)#i', $value, $match))
        {
            if (substr($match['id'], -4) != '.php')
            {
                $value = $match['id'];
            }
        }

        if (!preg_match('/^[a-z0-9\.]+$/i', $value))
        {
            $error = new XenForo_Phrase('please_enter_valid_facebook_username_using_alphanumeric_dot_numbers');
            return false;
        }

        return true;
    }

    public static function verifyTwitter(array $field, &$value, &$error)
    {
        if ($value[0] == '@')
        {
            $value = substr($value, 1);
        }

        if (!preg_match('/^[a-z0-9_]+$/i', $value))
        {
            $error = new XenForo_Phrase('please_enter_valid_twitter_name_using_alphanumeric');
            return false;
        }

        return true;
    }
}
 
message_user_info template:
PHP:
<xen:foreach loop="$userFieldsInfo" key="$fieldId" value="$fieldInfo">

Does anyone can tell me which fields have the array $fieldInfo when the field is a "Drop down selection" [value, text]?

Thanks ;)
 
Try to put it another way:

If for example the custom field has a [value, text] format (radio buttons, drop down selection, etc.), how I can access them [value, text] independently of each other?

If I put {$choice} in the 'Value Display HTML' field I can access to the [value] with:
PHP:
{xen:helper userFieldValue, $fieldInfo, $user, {$user.customFields.{$fieldId}}}
but then I can't access to the [text].

EDIT: I put the answer here: Custom Fields in message/message_user_info Template
 
Dude you really feel accomplished somehow by doing the dumb first post in every thread you can? Lets grow up can we?

Sure, I will do my best not to give you guys another chance to complain. My apologies to everyone who feels annoyed by such posts.

They say, voice of community is voice of God. I appreciate everyone's opinion on my excitement.
 
Ok, great ! :)

But it will be cool to have the option to put an image or icon instead of text.
for exemple : what is your favorite drink ? beer, coca... it will display an icon,
like that :

View attachment 19458

I had this on vB, I would like to have it on xenforo.

I'm after a similar result to this - I have users select their supported teams from user profiles. Each team has a .png file in a directory with the same name as the options in the userfield.
Is anyone able to help out with the template code to link in the images?
My custom field is called 'ShuteShield'

I've tried

Only, this doesn't populate with the value from the custom profile field, the image is just linked as
http://www.greenandgoldrugby.com/forum/images/icons/.png

rather than
http://www.greenandgoldrugby.com/forum/images/icons/Warringah.png
 
It would be great if we could use xen template syntax in the html output.

e.g.
PHP:
<xen:if is="$visitor.user_id == 1">
url: {$value}
</xen:if>
It would be amazing if we could do this, or possibly specify a template?

I'd also like to be able to populate a dropdown list dynamically using a callback.
 
I'm after a similar result to this - I have users select their supported teams from user profiles. Each team has a .png file in a directory with the same name as the options in the userfield.
Is anyone able to help out with the template code to link in the images?

My website isn't ready for the public yet, but here is what my use of this feature looks like: http://cyborgdinosaurs.com/xenforo/index.php?threads/the-mouse.28/#post-73

Here's what I did, although I put all the icons in a single image and used a CSS sprite. My field id name is GW2Profession. I wanted to hide the field name on the profile, so I added something specifically for the field to extra.css to make that 0 height and transparent.

The display HTML for it is: <div class="profimg {$value}"></div>

Note that what gets substituted for $value is what you entered for Text, not what you entered for Value.

In extra.css I added:

.pairsInline.userField_GW2Profession dt
{
color: transparent;
height: 0px;
}

.profimg
{
background-image: url("/images/imageblock.png");
background-repeat: no-repeat;
width: 25px;
height: 25px;
}

.profimg.Elementalist
{
background-position: 0px -40px;
}

.profimg.Warrior
{
background-position: -175px -40px;
}
etc.
 
@Kier

This looks great, but I missed something in the options. All new Custom User Fields where displayed as a part of the "Information" / "About" on the profile page (selected for to show there). It would be great to have another type of Custom User Fields to select as a title. So you would be able to create pages with an order like:
  • Signature
  • About
  • Home Cinema
  • Computer Equipment
  • Something else
  • Interact
and a lot of fields in that ...

I hope you understand what I mean :)

With that for me your Custom User Fields were perfect ;)
I agree. Some sites have tons of custom profile fields. For vB I made a mod that moved them to their own separate pages for editing. That allows sites who use the fields like PC / car / character specs, AND have multiples of said items, to arrange them neatly. In otherwords, one edit page for the PC specs of their main rig (say, custom profile fields 5-10), another page for their HTPC box (say, custom profile fields 11-16), etc.

Yeah, a separate database table with a one to many ratio would be better for something like this, but baby steps :)

If any of the above ideas are done by XF / a developer, then an evolution of this would be an optional way to select which spec page (or select multiple ones) to show in the postbit area. I was thinking that the easiest way to do it would be like how a user's name when clicked pops up a mini-profile with the information from that page.
 
Top Bottom