# How to detect user's location automatically and capture it in hidden field?

**URL:** <https://community.gravityforms.com/t/how-to-detect-users-location-automatically-and-capture-it-in-hidden-field/12053>\
**Category:** Get Help\
**Tags:** custom, salesforce, hidden, geolocation\
**Created:** [February 25, 2022, 4:49am UTC](https://community.gravityforms.com/t/how-to-detect-users-location-automatically-and-capture-it-in-hidden-field/12053 "2022-02-25T04:49:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user611c7c135e0ce407](https://avatars.discourse-cdn.com/v4/letter/u/ea666f/32.png) [@user611c7c135e0ce407](https://community.gravityforms.com/u/user611c7c135e0ce407)\
**Post date:** [February 25, 2022, 4:49am UTC](https://community.gravityforms.com/t/how-to-detect-users-location-automatically-and-capture-it-in-hidden-field/12053/1 "2022-02-25T04:49:40Z")

</div>

Hi all,

I am using gravity forms for collecting user details. I also want to collect the user’s state name and country without asking them to manually enter it. This data i want to capture in hidden fields and send it to salesforce.

As per the resources online I went ahead and installed these plugins-

1. Geolocation IP Detection

2. Geolocation Detector for Gravity Forms

after installing i am facing issues. I can now see “geolocation” in advanced fields but when dragged it in the form, I can not see any field settings for it. Nothing happens when I click on that field. Contacted author, no response.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/8/822f3635a75aef116ee2a9eb0c898cb7b817b3b1.png)

Has anybody used this plugin ? or developed the feature from scratch using code?

Note: Since Gravity forms collects IP address i also looked if its possible to send it to SF directly and then SF can get the state and country name from it. But i have no knowledge in salesforce.  
let me know which method is better here.

Any help is highly appreciated!

---

<div class="post-metadata">

**Author:** ![ajtatum](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/ajtatum/32/3435_2.png) [@ajtatum](https://community.gravityforms.com/u/ajtatum)\
**Post date:** [March 1, 2022, 5:22pm UTC](https://community.gravityforms.com/t/how-to-detect-users-location-automatically-and-capture-it-in-hidden-field/12053/2 "2022-03-01T17:22:07Z")

</div>

So, I have implemented a solution as when I was looking for something similar, I couldn’t find a plugin that seemed up to date. It’s a code snippet that fires after a entry has been saved, but before it gets sent to your CRM (in my case ActiveCampaign). I did it this way so that I wouldn’t have to pay for IP lookups every time someone went to a form… only when the form is saved.

Basically, I add “Administrative Only” fields to a form and then have them populated after making an API call.

Here’s my solution: [wordpress-snippets/add\_geolocation\_to\_form\_entry.php at main · AJTatumDigital/wordpress-snippets · GitHub](https://github.com/AJTatumDigital/wordpress-snippets/blob/main/gravity-forms-snippets/add_geolocation_to_form_entry.php)

Feel free to ask any questions or suggest any improvement!

---

<div class="post-metadata">

**Author:** ![user611c7c135e0ce407](https://avatars.discourse-cdn.com/v4/letter/u/ea666f/32.png) [@user611c7c135e0ce407](https://community.gravityforms.com/u/user611c7c135e0ce407)\
**Post date:** [March 2, 2022, 3:25am UTC](https://community.gravityforms.com/t/how-to-detect-users-location-automatically-and-capture-it-in-hidden-field/12053/3 "2022-03-02T03:25:08Z")

</div>

thanks for solution! @ajtatum . this is exactly what i was looking for. I will implement this from my end and let you know if i have any questions.

---

<div class="post-metadata">

**Author:** ![bethannon](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bethannon](https://community.gravityforms.com/u/bethannon)\
**Post date:** [March 3, 2022, 2:34am UTC](https://community.gravityforms.com/t/how-to-detect-users-location-automatically-and-capture-it-in-hidden-field/12053/4 "2022-03-03T02:34:34Z")

</div>

How will you deal with the applicable privacy laws with this data?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [April 2, 2022, 2:34am UTC](https://community.gravityforms.com/t/how-to-detect-users-location-automatically-and-capture-it-in-hidden-field/12053/5 "2022-04-02T02:34:56Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
