Skip to Content Skip to Menu

Getting visitors country from their IP

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
8 years 8 months ago #288362 by ricco1
Hi,

How could we have the country field pre-populated with the visitor's country guessed from their IP?

Thank you

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 49447
  • Thanks: 8467
  • Karma: 1465
8 years 8 months ago - 8 years 8 months ago #288371 by krileon
Replied by krileon on topic Getting visitors country from their IP
Probably with JS on the registration page that changes the fields value based off the results of the JS. There's several ways to do this with JS or jQuery. CB Auto Actions can be used to add JS or jQuery to the registration page using a Code action on the registration form display trigger. Several examples below.

stackoverflow.com/questions/3489460/how-to-get-visitors-location-i-e-country-using-javascript-geolocation

You might be able to use PHP in a code action as well if you handled setting the reference variables under the Parameters tab of the action for the trigger then modified the reference user object to set the fields value. For onBeforeRegisterFormDisplay the reference and user object variable would be Variable 1. Then in your PHP code for example you could modify that reference user object as follows.

Code:
$vars['var1']->set( 'FIELD_NAME', 'VALUE' );


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 8 years 8 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
8 years 8 months ago - 8 years 8 months ago #288390 by ricco1
Replied by ricco1 on topic Getting visitors country from their IP
What would you choose? PHP, JS or jQuery.

We intend to hide the country field from the reg form, in the same time save the user's country and let them choose later on edit.

Thank you.
Last edit: 8 years 8 months ago by ricco1.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 49447
  • Thanks: 8467
  • Karma: 1465
8 years 8 months ago #288416 by krileon
Replied by krileon on topic Getting visitors country from their IP
I wouldn't bother putting it on registration at all in that case. I'd act on the after registration trigger using PHP to do all of that behind the scenes then just store it to the user object.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: ricco1

Please Log in or Create an account to join the conversation.

  • ricco1
  • ricco1
  • OFFLINE
  • Posts: 310
  • Thanks: 8
  • Karma: -7
8 years 8 months ago - 8 years 8 months ago #288430 by ricco1
Replied by ricco1 on topic Getting visitors country from their IP
I think this is too big for us unless you can give us some more guidance please.
Last edit: 8 years 8 months ago by ricco1.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 49447
  • Thanks: 8467
  • Karma: 1465
8 years 8 months ago - 8 years 8 months ago #288431 by krileon
Replied by krileon on topic Getting visitors country from their IP
Beyond the below initial Code action setup no I can't help you any further. We do not provide custom coding here. Only simple examples.

Global
Triggers: onAfterUserRegistration
Type: Code
User: Automatic
Access: Everybody
Action
Method: PHP

You'd then write the code to find their country and store the result in their CB user object (as a field value).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 8 years 8 months ago by krileon.
The following user(s) said Thank You: ricco1

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum