Location search trick with Views exposed form elements

Posted on July 13, 2010 at 12:00 pm

We are just about to add have recently added location-based services to the BeGrand.net website and will be offering a way to search for events close to your post code.

As part of the build we’re using the excellent Location module which provides a proximity search by default. The latest version at time of writing is 6.x-3.1.

We have an exposed block that provides the basic search form and this leads to a Google map displaying events nearby – so you can search for events within 10 miles of CB24 for example. The search works well, but I wanted a way of displaying the filter on the output page. I knew that I could specify PHP code in the header for the view on the page in Views, but struggled to find the code I needed to return the post code, distance and units to show. Finally, I found the answer. Here it is:

[php]
<?php
$view = views_get_current_view();
if (isset( $view->exposed_input['distance'])) {
echo "<h2>Upcoming events within ";
echo $view->exposed_input['distance']['search_distance']." ";
echo $view->exposed_input['distance']['search_units']."s of ";
echo $view->exposed_input['distance']['postal_code']."</h2>
";
} else {
echo "<h2>All upcoming events</h2>";
}
?>
[/php]

So now, when you search within 10 miles of CB24 the header is displayed as:

Upcoming events within 10 miles of CB24

I’ve added a conditional statement so that an alternative header is displayed if the filter hasn’t been set.

Job done, which is nice.

Tags: , ,

12 Responses to “Location search trick with Views exposed form elements”

 
  1. Free website directory, Web directory. Add your website into free web directory and improve your search engine ranking and search engine position….

    [...]Location search trick with Views exposed form elements « SlashZero Limited[...]…

  2. Heart health says:

    Salutations…

    I pondered leaving this pingback awesome feature…

  3. Skipflyz2 says:

    Wordlistz2…

    Great blog post, saw on…

  4. Super article…

    I do agree with all of the ideas you’ve offered in your post. They are really convincing and can definitely work. Nonetheless, the posts are too short for beginners. Could you please lengthen them a bit from next time? Thank you for the post….

  5. Hard Day…

    It was a really really tough day for me today, so I decided just now to take to messing around for a while online and very fast I realized…

  6. Weebly article…

    I saw a writer writing about this on Weebly and it linked to…

  7. Fine article…

    What i don’t understood is actually how you’re now not actually much more smartly-preferred than you might be now. You’re so intelligent. You know thus significantly in relation to this topic, made me for my part believe it from a lot of various ang…

  8. Tumblr and Digg…

    Tumblr and Digg just now linked to this super interesting website…

  9. Bing results…

    While searching Bing I discovered this page in the search results and I didn’t think it match…

  10. I just want to mention I am just all new to blogging and really enjoyed your web blog. Likely I’m planning to bookmark your blog post . You actually have impressive articles and reviews. Thanks a bunch for sharing with us your web page.

  11. I simply want to mention I’m very new to blogs and really savored you’re blog site. Very likely I’m likely to bookmark your site . You amazingly come with fantastic writings. Regards for sharing with us your web page.

  12. The site…

    I like what you guys are up too. Such intelligent work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my web site :) ….

 

Leave a Reply