Hi there,
How do you add the Google maps autocomplete feature to the built in contact form (or any form)? I’ve tried a couple things with your built in one and Contact Form 7, but I can’t seem to get it to work. I want addresses to show up as a user starts to type an address into the form.
Thank you!
Creating a form from scratch and using a code block with the following code seems to work, but how could I put this into the theme so that it’ll work with other forms? The author here says that you can put it into the footer.php file: https://nerdygoodness.wordpress.com/2012/07/13/auto-searching-for-places-using-google-maps-javascript-api-v3-places-autocomplete/
<!– Google Maps API Stuff –>
<script src=”http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places” type=”text/javascript”></script>
<script type=”text/javascript”>
function initialize() {
var input = document.getElementById(‘location_field’);
var autocomplete = new google.maps.places.Autocomplete(input);
}
google.maps.event.addDomListener(window, ‘load’, initialize);
</script>
<!– Ends Google Maps API Stuff –>
<form>
Location: <input type=”text” id=”location_field” name=”location_field” />
</form>
Hey!
If it needs to go in the footer.php file then maybe around line 182 would work.
Or if you want to do it in a child theme then you could try adding this to your functions.php file.
add_action( 'wp_footer', 'enfold_customization_footer_scripts' );
function enfold_customization_footer_scripts() {
?>
insert your script here
<?php
}
Regards,
Elliott
Thank you for this, I’ll test it when I get time and see if it works.
We looking forward to hearing from you :)
Regards,
Josue