Example Form
If you use forms on your WordPress site, you will probably use a plugin to generate them. In most cases, the form plugin will provide you a shortcode that will somehow look like this: [form-xyz id="1"]
. You can then use this shortcode to place the form somewhere on your pages or posts.
You can help the user to fill out the form by providing an interactive map. You can place this map either below or above your form. You will then end up with two shortcodes on your site:
[interactive_map id="1"]
[form-xyz id="1"]
We assume that our select field has the following HTML:
<select id="location"> ... <option value="newyork">New York</option> ... </select>
The next step is to tell our map what has to be done when the user interacts with the map. The plugin allows to execute JavaScript code when a marker is clicked. The code for setting a select field value is quite simple. All we need is the following line:
jQuery("#location").val(click_value);
There are two critical parts in this code that have to be changed on your site:
- In this example we used the selector
#location
which is basically the id of our select field. The selector depends on the form and the plugin that you use. You will have to look at the HTML of your form to identify the correct field. - The plugin allows to store additional information for each marker in the
click_value
variable. In this example we use theclick_value
to store the option value of the corresponding select entry.Therefore, for New York we will store “newyork” in the click value. This will then set the select field to “New York” whenever the user clicks on New York.
If you have problems to find the right selector or option values contact us and send us the url of a page that contains the corresponding form. We will then send you the right selector for your form.
The map configuration can be found here:
Comments
If you need help or have questions, please leave a comment.