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
Gold

Hotel booking

Take a reservation for a hotel, motel, or apartment using this template Details
Gold

Complete the survey and get a selection of apartments in new housing in the city

Apartments in new buildings, on the secondary market, townhouses, Pass the survey and get a selection of apartments in new housing in the city, as well as in the secondary market. Details
Platinum

Selection of auto parts

Template in the form of a request, where the user can select a car brand, year of manufacture, specify data from the technical data sheet, contact details. You can edit the template to suit your needs. Details
Basic

Online appointment

Make an appointment with your customers or partners using the online appointment form. Details

Order turnkey form development

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