Simple Machines Community Forum

SMF Support => SMF 2.1.x Support => Topic started by: LWillisjr on January 02, 2023, 08:14:31 PM

Title: question on custom fields
Post by: LWillisjr on January 02, 2023, 08:14:31 PM
I am planning to convert our current 2.0.19 site to 2.1.3, and I have a test site with 2.1.3 up and running with a backup of our current forum data. We make use of the "Country Flags" mod which is not compatible with 2.1.x. I've read post on this forum suggesting creating a custom field which looks like a good alternative. I was investigating creating a new variable, anticipating I would need to write some code to populate the new variable with the country code.

However, I noticed the gender profile is already setup and seems to reference somehow the existing gender information in the members table (althought there is an entry in the smf_themes table for each member.

My question is why can't the same be done for the country information.
1. Create a custom contry field
2. Make it reference the current country code in the smf_members table
3. I realize a big input mask would be required to limit the country choices.
4. Where would the flag image files be placed and how to reference them?

Following is the existing setup for the gender field, and following that is my attempt to do something similar for the country field.

Current setup for the gender field which references gender images
gender_custom field.JPG

My attempt (which doesn't work) for something similar for country flags
country_custom.JPG 
Title: Re: question on custom fields
Post by: Kindred on January 02, 2023, 09:06:56 PM
Custom profile fields do not use the members table
You'd eitherhave to rewrite the mod or transfer the data to the themes table with the other custom field data

For location of the files
Quote{IMAGES_URL} - URL to images directory in the users current theme.
{DEFAULT_IMAGES_URL} - URL to the images directory in the default theme.

Also you would not use {country} for both the field name token text and for the display text...  i believe that {country} would refer to $txt['country'] in the language strings

I have
<span class="generic_icons gender_{INPUT}" title="{INPUT}"></span>And I have named each of the files to the same as the choices
Male, female, bigender, agender, demigod, demigirl, transgender,etc etc
And then I defined the span class in the css...  but you can use the img code that you list but for the alt and the displayed text, you'd use {INPUT}
Title: Re: question on custom fields
Post by: Sesquipedalian on January 02, 2023, 11:52:52 PM
In order to configure a custom profile field that will only accept a flag emoji as its input, set its Field Type to Text and set its Input Mask to Regex, and then use this regular expression for the mask:

~^[\x{1F1E6}-\x{1F1FF}]{2}$~
That will match exactly one flag emoji.

Alternatively, you could set the Field Type to Select and then populate the list of options with all the (current) flag emojis. But that will require you to update the list manually when the Unicode Consortium adds a new flag emoji.

Migrating the existing data from that mod into your new profile field will take a separate script. It should be pretty easy for a coder to write you a simple, one-time script to do that job. I suggest asking in the Help Wanted board; someone should be able to do it for you for a few bucks.
Title: Re: question on custom fields
Post by: Kindred on January 03, 2023, 12:14:21 AM
 I don't think the OP was looking for an entry of flag emojis into the field. I think the OP was asking for how to have a Choice Of countries and populate the field with the country Flag in the display, using country flag png images in the images directory
Title: Re: question on custom fields
Post by: Sesquipedalian on January 03, 2023, 03:13:50 AM
I misunderstood. :) In that case, @LWillisjr, you might want to try this: