Phone field with country flags

By: Sam Rossetti | Asked: 03/15/2024
ForumsCategory: General questionsPhone field with country flags
Sam RossettiSam Rossetti asked 8 months ago
Hello everyone, does anyone know about a way to implement an advanced phone field with country flags? Thanks for your feedback!
1 Answers
Victor Font answered 8 months ago
This is the second time this week someone has asked this same question. I do this on my own sites. You can see an example of it working here if you change the country select. https://formidable-masterminds.com/developers-directory/. I'll explain more in the comment below.
Victor Font replied 8 months ago

I use this formidable data to power the flag lookup in real time. https://formidable-masterminds.com/downloads/international-dial-codes/. This table is used as a dynamic lookup field everywhere phone or country is entered where you want to display the flag. You want a single source of truth for all lookup data in good software design.

The flags I use are all svg images that are downloadable for free. I can't remember where I found them. You'll need to Google free country flags. That's how I found them. They are all named xx.svg where xx is the 2-character ISO country code (lowercase). It's important to note the case. Hosting environment file structures are case sensitive. The 2-character ISO code in the curated lookup table is upper case.

When you use a dynamic lookup table, every field in the lookup entry is available because everything is linked by the lookup record's entry id. The coding logic to follow is to retrieve the 2-character ISO code from the lookup table, convert the uppercase string to lower case and concatenate the file path and ".svg".

I also found a flag for the People of Planet Earth for the Formidable Developers that didn't enter their country into their Developers Directory enrollment entry. Lesson learned: make country a required field when building a global directory.

I would share my code with you if I could, but I just looked up where the flag code is in my library and it's deeply embedded in the Formidable Masterminds Developers Directory core code. It's not going to be easy for me to decouple and convert it to a generic version that can be configured to be used on another site. It would take a paid project for me to consider changing code like that. But I told you how I did it as best as my memory serves and I could pick up from reading the early source code. Maybe that's all the guidance you need. Good luck.

Sam RossettiSam Rossetti replied 8 months ago

Thank you very much for this detailed explanation. Do you happen to know if there is somewhere a good explainer on how to extend FF fields with custom ones ?

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right