Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #424973

    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!

    #425005

    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&#8221; 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>

    #425460

    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

    #438625

    Thank you for this, I’ll test it when I get time and see if it works.

    #439476

    We looking forward to hearing from you :)

    Regards,

    Josue

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.