Skip Navigation

[Resolved] How to add a map to a form which appears by default

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Waqar 2 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2253755
Bildschirmfoto-2021-12-28-um-00.14.44.jpg

Hi there, I would like to have a map in the form, which shows by default a city map with a default set of longitude, latitude and zoom level and let the user position a map point there without entering an address - how ist this possible?

Regards and thanks in advance

I do this at the moment with gravity forms, but want to switch to your form. Attached you find, how this looks in gf.

#2253987

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

If your goal is to set the current visitor's location as a default address in the Toolset Form's address type field, you can follow these steps:

1. In Toolset plugins, you can use the "wpv-geolocation" plugin to get the current visitor's location after his/her consent:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-geolocation

You can wrap your form's shortcode within this shortcode, so that the form is only shown after the visitor has given the consent to use his/her location:


[wpv-geolocation]
[cred_form form="form-name"]
[/wpv-geolocation]

Note: You'll replace "form-name" with the actual name of your form.

2. Next, you'll need a custom shortcode, to extract the current visitor's location coordinates from the browser's cookies, (provided that the visitor has given the consent to use his/her location):


add_shortcode('get_current_user_location', 'get_current_user_location_func');
function get_current_user_location_func() {
	$output = $_COOKIE['toolset_maps_location'];
	return $output;
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

3. The last step would be to use this shortcode [get_current_user_location] in the "Field default value" of the address type field in the form.
( example screenshot: hidden link )

As a result, when the form will load, the address field will automatically show the current visitor's location selected with the map marker on the map.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2254891
Bildschirmfoto 2021-12-29 um 18.07.53.png
Bildschirmfoto 2021-12-29 um 18.14.42.png

Hi Waquar,

thank you for your help!
Sorry for the misunderstanding. I do not want to get the user location, but I what so show a map of a city and collect map points with suggestions or issues concerning a street, a place and so on.
I have attached a screenshot of the form, which I use in gravity forms, but which I want to replace with toolset.
It should look similar in toolset.
How can I do this?

Regards
Jutta

#2255471

Hi Waqar,
do you have an update on that?
Thanks

#2255849

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

screenshot-1.png

Thank you for sharing further details.

In the Toolset's address type field's settings in the form, you can set the default location for example a city name, e.g. "New York, NY, USA".
( example screenshot attached: screenshot-1.png )

When the form will load the map field will start with the map of New York City and the user can zoom in/out and drag the location pin to the exact location as needed.

It doesn't matter if the location text input field or the drag and drop pin is used to set the location, the exact latitude and longitude coordinates are saved in the background.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.