How to Capture Country Code with Phone Field [RESOLVED]

Good Day!

We have a phone field in our form. It’s using the International format which essentially allows the inputter to type any number of digits and symbols into the phone field.

Above method is great, but does not guarantee we’ll capture the inputter’s country code (i.e., calling code).

So, does anyone know how to best capture the country code in the frontend/backend based on the input phone number? We have installed and tested many plugins, but they all have one or several drawbacks.

Any suggestions (e.g., code snippet, filter, plugin) that will allow us to capture the country code?

For now, our best solution is to add a “City, State, and Country” (short address) field in our form to help out.

Thank you!

Hi Jonathan. How about one of these plugins?

1 Like

Thank you, @chrishajer!

We had previously tested the plugins you shared, and none seemed to work well at first.

So we decided to give the plugin, Smart Phone Field for Gravity Forms, another run (with a few adjustments and lots of testing performed) and now works beautifully.

In order for the plugin to function properly, these are the plugin adjustments that users need to make after activation:

(1) Go to: Phone field > Settings > General > and click on “Enable smart phone field” and “Automatically select countries”, then enter your default country. In our case, United States.

(2) Go to: Phone field > Settings > Advanced > and enter any country code in the Default Value field. In our case (US), we entered +1.

(3) When testing the plugin (frontend), and you purposely enter the wrong number for a given country, the form will display a message that says: “Invalie number” Obviously, this is a typo (should say “Invalid number”) and can be corrected as follows:

(a) Go to: /public_html/wp-content/plugins/smart-phone-field-for-gravity-forms/frontend/js/spf_main.js

(b) In edit mode, search for the keywords or term: “Invalie number” in the above file and change it to “Invalid number

Voila!

You got yourself an amazing new Phone field feature integrated into your form.

Wanna see the above in action? Visit: Book Us | Omnia Aerospace

Hope this helps. Again, thanks @chrishajer!

Cheers!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.