• Resolved freshcreate

    (@freshcreate)


    The plugin works so well, though missing one item that I need: Would it be possible to set up this plugin to work with query variables?

    So if I set up a form on some other page which directs to www.mysite.com/results-page/?address=new+york, it would fill in the field from the Simple Locator shortcode and display the map to those results.

    Any tips would be greatly appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter freshcreate

    (@freshcreate)

    Here is how I pulled it off. Might be hacky, would be curious if someone knows of a better way:

    	//grab parameter from url
    	function getParameterByName(name) {
    	    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    	    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    	        results = regex.exec(location.search);
    	    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    	}
    
    	//if parameter exists, fill the search field with that parameter
    	if (window.location.search.length) {
    		$(".address-input input").val(getParameterByName("address"));
    	}
    	
    	//prevent infinite loop that happens when triggering form click
    	var count = 0;
    	setTimeout(function() {
    	  if (count == 0) {
    		$(".submit button").trigger('click');
    	    count++;
    	  }
    	}, 500);

    @freshcreate

    Thank you for the tip. I would have do the same way, using js to capture the url parameter then trigger the submit button to launch the form.

    @freshcreate
    can you please explain more about this search query topic
    my email is [email protected]

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Search from external page using query variable’ is closed to new replies.