Reply To: Auto complete postal code

Home Forums Quform WordPress Auto complete postal code Reply To: Auto complete postal code

#32110
starwedd
Participant

Yes, thank you . My coder is in Bangladesh and was able to do so overnight. He changed the coding completely using the Snippets plugin I had downloaded so I am sharing here in case it can help anyone. I removed my API Key however I am not sure how to replace where it reads “72sold” in the code (since that is part of my website name) – Perhaps you can edit to make it usable for other Quform subscribers? I hope this is helpful as I could not locate online how to do this. See below:

add_action( ‘wp_footer’, function () { ?>
<script type=”text/javascript” src=”https://maps.googleapis.com/maps/api/js?key=YOUR API KEY GOES HERE&libraries=places”></script>
<script type=”text/javascript”>
function initialize72sold() {
var address72sold = document.querySelector(‘.quform-field-1_6’);
var options = {
types: [‘address’],
componentRestrictions: {
country: ‘us’
}
};
autocomplete = new google.maps.places.Autocomplete(address72sold, options);
google.maps.event.addListener(autocomplete, ‘place_changed’, function() {
var place = autocomplete.getPlace();
for (var i = 0; i < place.address_components.length; i++) {
for (var j = 0; j < place.address_components[i].types.length; j++) {
if (place.address_components[i].types[j] == “postal_code”) {
document.querySelector(‘.quform-field-1_7’).value = place.address_components[i].long_name;
}
}
}
});
}
google.maps.event.addDomListener(window, “load”, initialize72sold);
</script>
<?php } );

Be inspired. © 2020 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy