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

Form of agricultural land lease

This template of the form of the land lease agreement Details
Gold

Mortgage Calculation

Template for mortgage calculation by annuity or differential payment Details
Platinum

Best Actor of the Last Decade

​Install the voting form on your site and find out what users think Details
Basic

Service evaluation form

The client will fill in the form and you will be able to take into account all the comments. Details

Order turnkey form development

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