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
Basic

Make an appointment to see a dentist

Make an online appointment with the dentist Details
Platinum

The story of your career

Play-based testing template will help your users find out what kind of career he is developing: drama, comedy or action Details
Free

Applying for a driving course

Choose the necessary courses in the driving school, making an application and the manager will contact to confirm the chosen course. Details
Basic

Online tire service record

Specify the dates of your tire fitting in the template, add the lockout time and receive requests from customers Details

Order turnkey form development

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