Created
January 8, 2015 15:56
-
-
Save ksnider/df72bed5ba19a60ff7c9 to your computer and use it in GitHub Desktop.
Gets GeoIP information, when available, and writes to designated fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//theapiguys.com/scripts/geoip/location.php"></script> | |
<script type="text/javascript"> | |
$ = jQuery; | |
$(document).ready(function () { | |
//Hides these form fields | |
jQuery('#inf_field_City').parent().parent().hide(); | |
jQuery('#inf_field_State').parent().parent().hide(); | |
jQuery('#inf_field_Country').parent().parent().hide(); | |
jQuery('#inf_custom_TimeZone').parent().parent().hide(); | |
jQuery('#inf_custom_IPAddress').parent().parent().hide(); | |
// Hides the form field labels | |
jQuery('label[for=inf_field_City]').parent().parent().hide(); | |
jQuery('label[for=inf_field_State]').parent().parent().hide(); | |
jQuery('label[for=inf_field_Country]').parent().parent().hide(); | |
jQuery('label[for=inf_custom_TimeZone]').parent().parent().hide(); | |
jQuery('label[for=inf_custom_IPAddress]').parent().parent().hide(); | |
// Populates the hidden fields so they can be updated in Infusionsoft when submitted | |
var populateFields = { | |
'inf_field_City': GeoLocation.City, | |
'inf_field_State': GeoLocation.State, | |
'inf_field_Country': GeoLocation.Country, | |
'inf_custom_TimeZone': GeoLocation.Timezone, | |
'inf_custom_IPAddress': GeoLocation.IPAddress | |
}; | |
$.each(populateFields, function (id, val) { | |
id = '#' + id; | |
if ($(id).length && ! $(id).val()) $(id).val(val); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment