Appearance
Search form tag
Search your location via user form
The settings of the tag (channel, status, metric, result_url and the field names) are added to the form as hidden fields with a signature. A visitor can't change them: a form with changed settings is refused. Build the form with this tag, a hand-written form that posts to the search action is refused as well. A page that is cached from before the update to 4.0.0 has to be cleared, so the form gets its signature.
A visitor (IP address) can do a limited number of searches per minute (default 20, see Searches per minute); the searched location is cut off at 200 characters.
The tag
{exp:reinos_maps_locator:search_form}Tag Parameters
Below are the Tag Parameters. Those parameters can be used in the tag described above
search_id
set the search_id hash. This way the module will get this hash instead of using the hash from the url.
search_id=""metric
set the type of metrics km or mile (also mi or miles). Any other value uses km.
metric="km"channel
Give the channel(s) to search (channel short names). Separate with a pipeline (|) for multiple channels. Required: without a (valid) channel the search_result tag returns no results.
channel=""location_field
Set the location field name of your input field of your form. This will be used to search against the entries. Default location_field. The field can also hold a coordinate (52.1,5.1), see Use my location.
location_field="location_field"radius_field_max
Set the radius max field name of your input field of your form. Default radius_field_max.
radius_field_max="radius_field_max"search_type_field
Set the name of the search type field of your form. That field holds one of the values radius, locality, admin_level or sub_locality. When the field is not posted, radius is used. Default search_type_field.
search_type_field="search_type_field"search_category_field
Set the name of the category field of your form, that holds the categories (names or IDs) to search in. To search with more than one category (a location must then be in all selected categories, or in one of them with category_match="any" on the search_result tag), add [] to the name of the input field (e.g. <select name="search_category_field[]" multiple>); the parameter itself stays search_category_field. Default search_category_field.
search_category_field="search_category_field"result_url
set the url of your result page. The search hash is added to this url. Default is the current page. The search_result tag reads the hash from the first segment after the template; when that is not the case, use its search_id parameter. A search is deleted after 2 hours, so result links are temporary.
result_url=""status
Set the entry status search.
When you want to search for more than one status, use a pipeline | as separator
status="open"form_class
Add a class to the form, next to the default maps-search class.
form_class=""form_id
Set the id of the form. Default maps-search.
form_id=""method
Available from v4.0.0
post (default) saves the search and sends the visitor to the result page with a search ID in the URL (locations/result/<id>/). get sends the form straight to the result page with the search in the query string (locations/result?location_field=utrecht&radius_field_max=25): a link to the search can be shared or bookmarked, and the page can be cached. See Shareable searches.
method="get"Tag Variables
Below are the Tag Variables. Those Variables can be used inside the tag described above.
location
the location value
{location}radius
the radius value
{radius}search_type
the search_type value
{search_type}search_category:id
The Category id you are searching
{search_category:id}search_category
If searching multiple categories, this holds a loop of data
{search_category}
{search_category:search_category:id}
{/search_category}Use my location
Available from v4.0.0
A coordinate (lat,lng, e.g. 52.0907,5.1214) in the location field is used as is for a radius search: the geocoder is skipped, so the search costs no geocoding request. The other search types (locality, admin_level, sub_locality) still look up the address of the coordinate. With a coordinate, the address variables of current_search_location are empty.
This small script fills the location field with the location of the visitor's device and sends the form (the browser asks the visitor for permission first):
<button type="button" id="maps-my-location">Use my location</button>
<script>
document.getElementById('maps-my-location').addEventListener('click', function () {
var form = this.form;
if (!navigator.geolocation) {
return;
}
navigator.geolocation.getCurrentPosition(function (position) {
form.elements['location_field'].value = position.coords.latitude.toFixed(6) + ',' + position.coords.longitude.toFixed(6);
form.submit();
});
});
</script>Place the button inside the form and use the name of your location field (location_field by default).
Shareable searches
Available from v4.0.0
With method="get" the form has no hidden fields: the search is in the query string of the result page. Only the location, radius, search type and categories come from the visitor; set the channel, status and metric on the search_result tag (channel is required). The channel, metric and status parameters of this tag are not used then.
When you change the names of the fields (location_field, radius_field_max, search_type_field, search_category_field), set the same parameters on the search_result and current_search_location tags, so they read the same fields.
Every page view of a result page with a search in the query string counts for the Searches per minute setting, because it can be a geocoding request (the geocoder caches the locations it looked up before).
{exp:reinos_maps_locator:search_form method="get" result_url="locations/result" location_field="location" radius_field_max="radius"}
<input type="text" name="location" value="{location}">
<select name="radius">
<option {if radius == 10}selected{/if} value="10">10 km</option>
<option {if radius == 25}selected{/if} value="25">25 km</option>
</select>
<input type="submit" value="Search">
{/exp:reinos_maps_locator:search_form}On locations/result:
{exp:reinos_maps_locator:search_result channel="stores" location_field="location" radius_field_max="radius" radius="25"}
{title}: {distance} {distance_unit}
{/exp:reinos_maps_locator:search_result}Example
{exp:reinos_maps_locator:search_form
metric="km"
channel="channel_1|channel_2"
location_field="location_field"
radius_field_max="radius_field_max"
search_type_field="search_type_field"
result_url="locations/result"
}
<label>Location to search with (this location will be geocoded</label><br>
<input type="text" name="location_field" value="{location}"/>
<br><br>
<label>Radius (only uses when the search_type is set to 'radius')</label><br>
<select name="radius_field_max">
<option {if radius == 20}selected{/if} value="20">20</option>
<option {if radius == 50}selected{/if} value="50">50</option>
<option {if radius == 100}selected{/if} value="100">100</option>
<option {if radius == 5000}selected{/if} value="5000">5000</option>
</select>
<br><br>
<label>Search type</label><br>
<select name="search_type_field">
<option {if search_type == 'radius'}selected{/if} value="radius">Radius</option>
<option {if search_type == 'locality'}selected{/if} value="locality">Within a City</option>
<option {if search_type == 'admin_level'}selected{/if} value="admin_level">Within a state or province</option>
<option {if search_type == 'sub_locality'}selected{/if} value="sub_locality">Within a city_district</option>
</select>
<br><br>
<input type="submit"/>
{/exp:reinos_maps_locator:search_form}