Support

Account

Home Forums Bug Reports Google Map field / autocomplete error through frontend

Solved

Google Map field / autocomplete error through frontend

  • Hi there,

    after a day enthousiastically tinkering away with ACF and the new Google Maps field, I was really excited to have set up a front-end posting form in which visitors of my website will be able to post a custom content type with a set location.

    Unfortunately, everything seems to work except the location search. Only in the front-end! In the backend, it all works fine.
    Firebug says: “TypeError: google.maps.places is undefined”, and refers to line 1832 of input.js.

    Google helped me find this thread from a few days ago:
    http://support.advancedcustomfields.com/forums/topic/new-googlemap-field-doesnt-work/

    The problem Andamira describes there sounds exactly like what I get on the front end. Unfortunately her solution doesn’t help me.

    I did install a lot of plugins for testing, but to figure out what was causing my problem I deinstalled/deleted all of them, turned on WP error reporting, tried to recreate the problemless situation on another wordpress install, but no dice.

    My next course of action will be to create a completely fresh install of WordPress and try it again, but in the meantime, would you take a look?

    Kind regards
    Anneke

  • Hi @asinnema

    Thanks for the bug report.

    I’ll do some testing locally and et you know what I find.
    Please do setup a blank install to see if is some kind of conflict.

    Thanks
    E

  • Hi Elliot,

    thanks for your prompt reply!

    I retraced my steps on a clean (local) install; same problem.
    I retraced my steps on a test wordpress site, and things worked as I wanted.
    I then tried to retrace all the steps I took to create a form on my live site (in maintenance mode, it’s a bit of a mess) but now I get the following error when I submit a form from the front end:

    Warning: Cannot modify header information – headers already sent by (output started at /THEMENAME/page-full-width.php:8) in wp-includes/pluggable.php on line 899

    page-full-width.php is the template where I call the acf_form_head, and the form. So basically just:

    <?php 
    acf_form_head();
    get_header();
    ?>

    and after some html markup

    <?php 
    $options = array( 							'post_id' => 'new', 							'field_groups' => array( 31 ),  
    ); 
    if (is_user_logged_in()) { 
    acf_form( $options ); 
    }
    ?>

    I don’t think the above code is incorrect?

    In the functions.php I have the following:

    function my_pre_save_post( $post_id )
    {
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        } 
    
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_title'  => $_POST["fields"]['field_528a8d1ae2674'],
            'post_type'  => 'custom_type',
            'post_content' => $_POST["fields"]['field_528a8d1fe2675']  
        );  
     
        // insert the post
        $post_id = wp_insert_post( $post ); 
     
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
     
        // return the new ID
        return $post_id;
    }
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
     
    add_action( 'wp_print_styles', 'my_deregister_styles', 100 ); 
    function my_deregister_styles() {
        wp_deregister_style( 'wp-admin' );
    }

    The only fields I have set up in ACF to be used in the front-end form are title, content, and a map.

    Hope this helps! I will keep on tryin’ 😉

  • Hi @asinnema

    Thanks for the info.

    Your PHP warning states that on line 8 of the template file, your code is outputting some HTML before redirecting.

    Can you go through your code and comment out lines to find exactly the line of code which causes text to be rendered before ACF can redirect?

    Thanks
    E

  • Woohoo!

    Thanks to your pointer, I found out that the theme I use as a boilerplate was probably causing the mess with the big scary error I got.

    I have also done some more testing and I just discovered that the original problem I posted (which was: all of a sudden I can’t use autocomplete anymore on the post form), was caused by loading the javascript to the google maps api like this, in the footer:

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">

    I was loading the api in my theme’s footer.php file, and I have moved it to the actual page where I was using it. Problem solved!

    If you have a moment I wouldn’t mind a brief explanation why this is, as I’d love to be educated a bit more.

    Thanks for all the help!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Google Map field / autocomplete error through frontend’ is closed to new replies.