XF 2.3 Custom field management/coding

PaulProe

Member
We have a couple of different XenForo forums that include custom fields to gather the users' first and last names. It is then displayed in the user message box, in the posts Message_User area and also within their profile. We chose to separate the two names as they are a requirement to register and having a single field for name, we found we were often not getting the full name. Now, the issue

With the two names, is there a way to combine the two into one for posting on the forums? I know you can manipulate the SQL database (beyond my paygrade) and fill a third field, however we would have to deal with the nulls in the fields and also have to do this on a regular basis as new users are added.

Another way is if we could programmatically propagate a third custom field with the two names. Again, we would have to deal with nulls from back when this wasn't a requirement of the users. If the third custom field could be generated, then it is simple to add it to the user areas.

Open to ideas on how to approach this. I understand basic coding but I am not experienced with this in Xenforo or PHP.
 
This can be done with template edits/modifications where you want to display the full name data. You would just use a simple conditional check to make sure the data exists. No need for a full "add-on" for something simple like this.

Example:
Code:
<xf:if is="$xf.visitor.Profile.custom_fields.first_name AND $xf.visitor.Profile.custom_fields.last_name">
    {$xf.visitor.Profile.custom_fields.first_name} {$xf.visitor.Profile.custom_fields.last_name}
<xf:else />
    {$xf.visitor.username}
</xf:if>

The above code will display first name followed by last name, if they are both filled out, otherwise falls back to the normal username displayed. You would just need to replace the field ids first_name and last_name in the above code with whatever your actual field ids are.

You would implement this using a template modification or direct template edit for each place you'd like to replace where the username currently displays and where you'd prefer the full name.

This solution will work if you just have a few places you'd like to display the full name instead of username. If you want to replace it everywhere in XenForo you are looking at well over 20+ plus template edits. In that case the use of a macro would be better and creating a simple add-on would be a better way to go.
 
Back
Top Bottom