Home › Forums › Quform WordPress › Auto complete postal code
- This topic has 3 replies, 2 voices, and was last updated 4 years, 1 month ago by Ally.
- AuthorPosts
- October 26, 2020 at 10:19 pm #32105starweddParticipant
Thank you for providing the functions.php code for autocomplete of the address field. I originally had my site with QuForm (WordPress using Elementor) that had 2 fields that worked with autocomplete. One was the actual street address and the other field was the zip code (postal code) field which would complete upon the AutoComplete of the street address.
While updating site colors yesterday on my form I noticed that the autocomplete disappeared for both the street address field and the postal code field. Again, thanks to your post showing how to put in the functions.php code, the street address field works but the zip code does not autofill as it used to when the street address completes.
Is there any code that would do this? I haven’t been successful in reaching the person who setup my site so I am trying to get this to work again. My live site where the 2 fields appear at the top is 72sold.sellmyhomeasheville.com for visuals.
Thanks in advance for any guidance you may provide.
October 27, 2020 at 10:17 am #32108AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
October 27, 2020 at 12:15 pm #32110starweddParticipantYes, 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 } );October 28, 2020 at 9:42 am #32115AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.