Update a Google Maps object and focus on the address from a ninja form

19 Views Asked by At

I created a Wordpress page with, on the left side, a Paragraph bloc containing the ninja form [ninja_form id=2] object, and on the right side a Classic bloc containing the [wpgmza id="1"] WP Go Maps (formerly WP Google Maps) plugin. In functions.php of twentytwentyfour theme, I added the following code:

add_action( 'ninja_forms_after_submission', 'PES_display_google_maps' );

function PES_display_google_maps($form_data) {

// get address data seized by user
$address = $form_data['fields']['address_1707734289628']['value'];
$zip = $form_data['fields']['zip_1707734295238']['value'];
$city = $form_data['fields']['city_1707734296568']['value'];

// Google Maps url
$map_url = 'https://www.google.com/maps/embed/v1/place?key=MYGOOGLEKEY&q='. urlencode($address . ' ' . $zip . ' ' . $city);

// Supposed to display the map focused on the ninja form address
echo '';
}

My aim is to update the map and focus on the ninja form address, but that do not work as expected. Can you provide your advice on the change needed in this code ? Thank you in advance. Thierry

Versions : Worpress 6.4.3 Ninja Forms 3.8.0 WP Go Maps 9.0.34 Gutenberg 17.9.0

0

There are 0 best solutions below