Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@patrickfreitasdev
Last active November 6, 2022 00:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickfreitasdev/3e19d9693ab03ba577dea99955dd5573 to your computer and use it in GitHub Desktop.
Save patrickfreitasdev/3e19d9693ab03ba577dea99955dd5573 to your computer and use it in GitHub Desktop.
<?php
/**
* Usage: this set a hidden-2 field based on the hidden-1 IP
*/
add_action('wp_footer', function ()
{ ?>
<script>
(function ($) {
$(function () {
$(document).on("after.load.forminator", function (e, id) {
if(id === 1645){
let hidden_1 = `#forminator-module-${id} #hidden-1`;
let hidden_2 = `#forminator-module-${id} #hidden-2`;
let ip = jQuery(hidden_1).val();
var requestUrl = `https://www.iplocate.io/api/lookup/${ip}`;
$.ajax({
url: requestUrl,
type: 'GET',
success: function(json)
{
jQuery(hidden_2).val(json.country);
},
error: function(err)
{
console.log("Request failed, error= " + err);
}
});
}
});
});
})(window.jQuery);
</script>
<?php
}
, 21); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment