Automatic identification of phone number mask by ip

Good afternoon!

As you know, in the phone element we have added the possibility of selecting entering a phone number witha country flag:

Automatic detection of the phone number mask by ip 1

Automatic detection of the phone number mask by ip 2

Automatic detection of the phone number mask by ip 2

We were approached by users with a request - auto-detection of the country by ip.

To add such functionality, you need to add a script custom code:

Automatic detection of the phone number mask by ip 3

Select "Custom code" in the form settings and click "Open Script Manager":

Automatic detection of the phone number mask by ip 4

Click "Add Code":

Automatic detection of the phone number mask by ip 5

Specify a name for the new code, select the "Script coonnection point" - body...</body>, in the "Type of connection" list - On a form page:

Automatic detection of the phone number mask by ip 6

In the code field, you need to specify the following script:

<script>
function geoIpLookup(callback, countries) {
    $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
        var countryCode = (resp && resp.country) ? resp.country : "us";
        if (!countries.length || countries.indexOf(countryCode) !== -1) {
            callback(countryCode);
        } else {
            callback(countries[0] || countryCode);
        }
    });
}
</script>

Automatic detection of the phone number mask by ip 7

Where the parameter resp.country: "us", by default, the country is displayed if there is no country in the list of available countries for the phone number:

Automatic detection of the phone number mask by ip 8

Accordingly, instead of the value us (USA), you can specify a different value.

After you have added the script to the "Code" field, do not forget to click the "Save" button. The added code will be sent to the administrators for moderation:

Automatic detection of the phone number mask by ip 9

After the code is approved, the approved status will appear and then it can be connected to the form. Open the list of scripts that can be added to the form:

Automatic detection of the phone number mask by ip 10

Select the approved script and click "Add to Form":

Automatic detection of the phone number mask by ip 11

The code will be displayed in the "List of used scripts in the form", click "Save":

Automatic detection of the phone number mask by ip 12

Now, after opening the form, the value of the country code defined by the ip address will be set in the phone field:

Automatic detection of the phone number mask by ip 14

Comments
Ready-made templates of web forms
Platinum

Order a food package

Order a product kit with this template Details
Gold

Calculate the cost of washing your car and get a discount.

With this template in the form of a receipt, you can attract customers for service in your car wash. Template can be edited, added and removed fields Details
Platinum

Oceans of the Earth

The test allows you to learn the level of knowledge about the oceans of the Earth Details
Platinum

How well do you know the solar system?

Do you have a good understanding of the solar system? Take the test Details

Order turnkey form development

No time to figure out all the settings yourself? No problem!
Order web form development from us