Hello!
I am using the Advanced Post Creation addon with the Address field.
I would like to have a simple link to a Google Map without having to build out a custom function. The same “map it” link found in the entry view would be acceptable in my use case. Is this possible? I have attempted to use the [gravityform]
shortcode with urlparams found in this solution: https://community.gravityforms.com/t/display-address-value-in-content-and-or-map-dynamically-resolved/5381 but not working form.
Thank you.
Hi Frederick. Can you explain where you want to use this link to a Google Map? Are you showing that on the confirmation page, or sending that in the email notification, or something else?
Also, we’ll need to see your form (please share the URL to the page on your site where we can see the form) to know the IDs of the address parts that should be included in the link to Google Maps. Thank you
I want to use the this address link in the Advanced Post Creation feed under the Post Content section.
I have also included a Gist to the details of the issue.
I have received some offline help and assistance with the issue. But I know it can be better or there may be another solution.
Firstly, is there a way to call the Map It function that shows on the Entry View page into the Advanced Post Creation fields?
https://gist.github.com/oneblackcrayon/41712abe04c872e4924db7f31d7bf946
Hi Frederick. The function that creates the map it link is not callable, so you won’t be able to use that to create the link in your post body. This is what that code returns though:
"<br/><a href='http://maps.google.com/maps?q={$address_qs}' target='_blank' class='map-it-link'>Map It</a>";
That’s all there is to it. You combine all parts of the address field into one, and send the whole thing to http://maps.google.com/maps?q=
. That link in our code is outdated, and should be updated to this: https://www.google.com/maps/?q=
In your post body, it would look something like this, if I copied your merge tags correctly:
<a href='https://www.google.com/maps/?q={:10.1} {:10.2} {:10.3} {:10.4} {:10.5} {:10.6}' target='_blank' class='map-it-link'>Map It</a>
That’s a simple version of doing the same thing that the Gravity Forms core code is doing. Have you tried something like that?
Hello Chris,
This is the solution I came up with but I think I need to add the data to ACF.
Thank you for your example as it helped me figure out that I would want to urlencode
the data from the input fields first, then sanitize_text_field
to remove extra spacing.
add_action( 'gform_pre_submission_31', 'gf_address_fields_to_acf_fields' );
function gf_address_fields_to_acf_fields( $entry, $form ) {
// For use with ACF if possible
global $post;
global $wp_query;
$post_id = get_the_ID();
// End ACF additional code
$gf_address_fields = urlencode(
rgpost( 'input_10_1' ) .' '.rgpost( 'input_10_2' ) .' '.rgpost( 'input_10_3' ) .' '.rgpost( 'input_10_4' ) .' '.rgpost( 'input_10_5' )
);
$_POST['input_19'] = sanitize_text_field( $gf_address_fields );
error_log( print_r( $gf_address_fields, true ) );
// Let's save it so we can use it with ACF?
}
Very cool. Thank you for sharing.