2

I've been wrestling with this for too long and it's doing my head in now!

I am using the low search plugin for expressionengine and want to search: a) by keyword (which is working fine) b) by channel - selected by dropdown (which I can't get to work)

So the results would show channel entries with the relevant keywords ONLY in the selected channel.

Currently I have:

{exp:low_search:form 
        form_class="header-search"
        form_id="search-keywords"
        required="keywords"
        result_page="search/results"
}
            <select name="searchChannel">
                <option value="channel1|channel2">All</option>
                <option value="channel1">Channel1</option>
                <option value="channel2">Channel2</option>
            </select>
            <input type="text" name="keywords"id="keywords">
            <input type="submit">
{/exp:low_search:form} 

results page:

{exp:low_search:results 
   disable="{gv:disable_default}" 
   limit="18"
   orderby_sort="title|asc"
   query="{segment_3}"  
}

I can pass through the searchChannel field through to the results page by adding:

{low_search_searchChannel}

to the results page; and of course I can set the channel filter in the results page by hard coding it:

channel="channel1"

but if I try:

channel="{low_search_searchChannel}"

I get nothing. There's probably a better way anyway to pass it straight in via the form tag, but have tried everything I can think of!

Thanks in advance

1

There is no need to approach it like that. Low Search handles both native and custom parameters the same: like this. So any parameter can be an input field.

That means that if you name your select element channel, you're already done, eg:

<select name="channel">
  <option value="channel1|channel2">All</option>
  <option value="channel1">Channel1</option>
  <option value="channel2">Channel2</option>
</select>

No need to set the channel="" param on the Results tag, let alone for PHP in your template.

Better still, since you're using the Keywords filter, you might want to consider targeting the collection param rather than channel, eg:

<select name="collection">
  <option value="">All</option>
  {collections}
    <option value="{collection_name}">{collection_label}</option>
  {/collections}
</select>
| improve this answer | |
  • YAY!!! changed the select name and works a treat! helps if you've written the plugin I guess! ;op My fault for misinterpreting the documentation - useful to know for the future. Thanks very much :) – nick alexander Apr 30 '15 at 16:04
-1

Ahhh, good old parse order :)

{low_search_searchChannel} can't be parsed until it is inside of the {exp:low_search:results } I would suspect. How about a little PHP to get you out of stuck-ville?

PHP on Input

<?php 
    $query = ee()->uri->segment(3);
    $query = json_decode(base64_decode($query));
    //validate your channel here
    $channel = 'channel1|channel2'; //default
    if ( !empty ( $query->searchChannel ) ) { 
        $channel = $query->searchChannel;
    }
?>
{exp:low_search:results 
    disable="{gv:disable_default}" 
    limit="18"
    orderby_sort="title|asc"
    query="{segment_3}"  
    channel="<?php echo $channel ; ?>"
}

This should check if searchChannel was submitted (you can further check it where I put the comment) and fetch it into a PHP variable, completely seperate from low_search. on output if $channel is empty (perhaps someone tried to inject something and it got cleaned) it puts the default channels in, synonymous with your All option.

Give that a little try and see how you get on.

Edit

Added code to examplify how to decode the Low Search URL parameter...

PS> Making a site about biking or holidays per chance?? lol, I decoded your example from the comments, channel = tours, keywords = france.... :D

| improve this answer | |
  • I like your thinking, I know where I am better with PHP - none of this new fangled EE malarky! Unfortunately, if I echo out the ee()->input->post('searchChannel'), it comes out blank. I have checked PHP is enabled for the template and the PHP parsing is set to INPUT. – nick alexander Apr 30 '15 at 13:09
  • I'm wondering if low-search doesn't POST inputs, but passes them through encrypted in the URL as there is a big crazy string in the URL: results/eyJyZXN1bHRfcGFnZSI6InNlYXJjaFwvcmVzdWx0cyIsInNlYXJjaENoYW5uZWwiOiJ0b3VycyIsImtleXdvcmRzIjoiZnJhbmNlIiwieCI6IjAiLCJ5IjoiMCJ9 – nick alexander Apr 30 '15 at 13:15
  • Good point, this seems to be a redirect from an action. can you inspect the search form and tell us the action attribute please? This will tell us if it's posting to an action URL and forwarding you to big crazy string result page, or not. FYI, the big crazy string is a Base64 encoded JSON array, the one you posted is : {"result_page":"search\/results","searchChannel":"touróm8óm7s","keywords":"france","x":"0","y":"0"}, I'll factor this into my answer! – Blatant Apr 30 '15 at 13:37
  • Forget my last question, worked it out. Please see my edited answer above! That should get you there!! – Blatant Apr 30 '15 at 13:50
  • hehe! check out your hacking! yes, tour related site! Still no juicy I'm afraid... I think you hit the nail on the head with the 'parse order' diagnosis. Your edit does capture the input, but the trouble ee is having I think now is that if PHP is parsed on input, I believe all the PHP variables are parsed into strings before the EE code gets to run (I'm just guessing there), but if the PHP is parsed on output, the EE code will run without the parsed PHP (again, not TOTALLY sure on that). – nick alexander Apr 30 '15 at 14:43

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.