0

Just looking for a pointer in sorting out a search form.

I am implementing a property search form.

I have a search field and a couple of range filters, and a grouped category drop down.

See here...

{exp:low_search:form collection="cottages" class="walk-search-form" search_mode="all" query="{segment_3}" result_page="cottages/results"}

                    <label>Search for a cottage:</label>

                    <input type="text" name="keywords" id="keywords" class="span5" />



                    <label>Choose a county:</label>

                    <select name="search:cottage_county">
                      <option value="">Filter by Category</option>
                      {exp:channel:categories cache="yes" refresh="60" channel="cottages" disable="category_fields" style="linear"}
                      {if parent_id == '0'}{if count != '1'}</optgroup>{/if}<optgroup label="{category_name}">{/if}
                      {if parent_id != '0'}<option value="{category_id}">{category_name}</option>{/if}
                      {/exp:channel:categories}
                     </select>


                    <label>Sleeps a Max of:</label>

                    <select name="range:cottages_sleeps_max" class="span2">
                      <option value="">All</option>
                      <option value="1;">1 or more</option>
                      <option value="2;">2 or more</option>
                      <option value="3;">3 or more</option>
                      <option value="4;">4 or more</option>
                      <option value="5;">5 or more</option>
                      <option value="6;">6 or more</option>
                      <option value="7;">7 or more</option>
                      <option value="8;">8 or more</option>
                    </select>

                    <label>No of Beds:</label>

                    <select name="range:cottages_beds" class="span2">
                      <option value="">All</option>
                      <option value="1;">1 or more</option>
                      <option value="2;">2 or more</option>
                      <option value="3;">3 or more</option>
                      <option value="4;">4 or more</option>
                      <option value="5;">5 or more</option>
                      <option value="6;">6 or more</option>
                      <option value="7;">7 or more</option>
                      <option value="8;">8 or more</option>
                    </select>



                    <button class="btn btn-large btn-block btn-blue" type="submit">Search</button>

                {/exp:low_search:form}

So far the search field and the range dropdowns both work.

The category dropdown displays correctly, i.e.

Parent Cat
-child 1
-child 2
Parent Cat 2
-child 1

But when I perform a search on it, it returns every entry.

The other thing is that I want the category, and range values to remain selected once the search has been performed.

Low helped me before in a similar search form, but i've tried everything that was suggested there, but as this is a slightly different scenario, they don't seem to be working :(

UPDATE

OK I seem to have the category search working.

Changed <select name="search:cottage_county"> to <select name="category:cottage_county">

This returns the right results, but is there a way for me to display the name of the category that they selected in the results page?

1

Yeah, the syntax for the grouped category search filter is category:group_name, not search:group_name. The latter is the native search:-parameter.

And in this case, you don't even need to use the grouped category filter, as you only have a single group. The grouped category filter allows you to combine AND and OR queries, which requires at least 2 groups. Therefore, you could just use name="category", the native category parameter.

To show the category name, you'll need to use the channel:categories tag. The {low_search_category} variable will contain a pipe-separated list of selected category IDs, so use the tag to get the corresponding names. Something like this:

{exp:channel:categories show="{low_search_category}"}

Be sure to use that inside either the Results tag, the Form tag or the Filters tag.

| improve this answer | |
  • Thanks for that Low, I had just come on here to say how I had solved it. I'll add it as an alternative answer. – shorn Apr 28 '13 at 10:06
0

If the category shows up in the URL then you can easily pull it out with Low Seg2Cat:

{segment_n_category_name}
| improve this answer | |
  • Yea, the category is not showing in the URL, I have a huge url results string. Is there a way to change that so that the cat ID shows? – shorn Apr 27 '13 at 9:44
  • Ah, I presume it's outputting a random string of characters on the search results page? As far as I know it's not possible to change that URI but you could always use a little JavaScript to grab the selected category and output that on the page. – Ian Apr 27 '13 at 10:04
  • Yea random string is correct. I'll keep looking into it! – shorn Apr 27 '13 at 10:07
  • You could always Stash the selection and pull it out in your template if you wanted to stick to the server-side and template output. – Ian Apr 27 '13 at 12:25
  • Unfortunately I have never been able to wrap my head around using Stash! :( – shorn Apr 27 '13 at 20:56
0

OK, Low has provided an answer to my question, but'll explain how I have just managed to solve this. My way is probably not the most optimised or efficient way, but it's working!

Firstly, to get the category name. I used Mark Croxton's Cat2 plugin.

exp:cat2:name category_id="{low_search_category:cottage_county}"} was all I needed to change the id to the name. I think this is essentially the same principal as using the channel:categories tag that Low has suggested.

My other issue was the "range" search dropdowns.

I managed to get this to keep the values once a search had been performed by using this in the form:

<select name="range:cottages_sleeps_max" class="span2">
    <option value="">All</option>
    <option value="1;" {if "1;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>1 or more</option>
    <option value="2;" {if "2;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>2 or more</option>
    <option value="3;" {if "3;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>3 or more</option>
    <option value="4;" {if "4;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>4 or more</option>
    <option value="5;" {if "5;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>5 or more</option>
    <option value="6;" {if "6;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>6 or more</option>
    <option value="7;" {if "7;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>7 or more</option>
    <option value="8;" {if "8;" == "{low_search_range:cottages_sleeps_max}"} selected="selected"{/if}>8 or more</option>
</select>

and then this in the results:

{if low_search_range:cottages_sleeps_max}Sleeps 
  {if low_search_range:cottages_sleeps_max == "1;"}<strong>1</strong> or more.{/if}
  {if low_search_range:cottages_sleeps_max == "2;"}<strong>2</strong> or more.{/if}
  {if low_search_range:cottages_sleeps_max == "3;"}<strong>3</strong> or more.{/if}
  {if low_search_range:cottages_sleeps_max == "4;"}<strong>4</strong> or more.{/if}
  {if low_search_range:cottages_sleeps_max == "5;"}<strong>5</strong> or more.{/if}
  {if low_search_range:cottages_sleeps_max == "6;"}<strong>6</strong> or more.{/if}
  {if low_search_range:cottages_sleeps_max == "7;"}<strong>7</strong> or more.{/if}
  {if low_search_range:cottages_sleeps_max == "8;"}<strong>8</strong> or more.{/if}
{/if}

Again, I'm not entirely sure that this is the way it should be done. But it's working solidly.

| improve this answer | |
  • You can also consider using Loopee for populating those lists: github.com/danott/ee-loopee and perhaps use Low Replace to strip away the semi-colon instead of that heap of conditionals. – Low Apr 28 '13 at 10:19
  • Ahh, great tip. I shall do that! – shorn Apr 28 '13 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.