All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Filtering results via checkbox field using AND/OR

Stephen 23 Jul 2012 13:52 question, complete

Hi Low,

I'm probably going about this in the wrong way, but just wanted to see if you could offer me any advice please.

I've got an advanced search form that allows a user to filter events by day. This day field is a P&T Checkbox field. It's checked if the event is taking place that day.

The following code works like an AND search, so if a user checks Thursday and Friday, it will output events that are taking place on Thursday AND Friday.

Can you think of a way I can change this, so that it outputs events that are taking place on Thursday OR Friday instead?


<h3>Search by dates:</h3>

<label><input type="checkbox" name="search:cf_directory_opening_times_thu" value="not IS_EMPTY"{if low_search_search:cf_directory_opening_times_thu == "not IS_EMPTY"} checked="checked"{/if} /> Thursday</label>

<label><input type="checkbox" name="search:cf_directory_opening_times_fri" value="not IS_EMPTY"{if low_search_search:cf_directory_opening_times_fri == "not IS_EMPTY"} checked="checked"{/if} /> Friday</label>

<label><input type="checkbox" name="search:cf_directory_opening_times_sat" value="not IS_EMPTY"{if low_search_search:cf_directory_opening_times_sat == "not IS_EMPTY"} checked="checked"{/if} /> Saturday</label>

<label><input type="checkbox" name="search:cf_directory_opening_times_sun" value="not IS_EMPTY"{if low_search_search:cf_directory_opening_times_sun == "not IS_EMPTY"} checked="checked"{/if} /> Sunday</label>


Thanks,

Stephen

Edit: 1password entered my email address into the title of the post by mistake when I used it to login after trying to post when logged out, so I deleted the previous post and posted it again...

Replies

  1. Low 23 Jul 2012 14:04

    Hi Stephen,

    I'm afraid that's not possible with this setup. If you look at the regular channel:entries tag, you can't use OR when defining multipe search:field parameters. That's why LS can't either.

    It would work if there was a single field (say, cf_directory_opening_times) which is a checkbox group. You could then use a parameter search:cf_directory_opening_times="thursday|friday" which would translate to "If the field contains either 'thursday' or 'friday'. That again would be usable as a LS form field, using Low Options, to something like this:

    {exp:low_options:cf_directory_opening_times} 
    {options}
    <input type="checkbox"
    name="search:cf_directory_opening_times[]"
    value="{option:value}
    {if '{option:value}' IN ({low_search_search:cf_directory_opening_times})}
    checked="checked"
    {/if} /> {option:label}
    {/options}
    {/exp:low_options:cf_directory_opening_times}

  2. Stephen 24 Jul 2012 01:07

    Hi Low,

    Thanks for the alternative idea. I'll look into altering the format of my data as that sounds like a good alternative.

    Thanks,

    Stephen