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

Support archive

Setting checked state in checkbox group field in a Low Search form

Stephen 1 Jul 2013 02:49 question, complete

Hi Low,

Is it possible to set the 'checked/active state' of a checkbox in a checkbox group field in a Low Search form? For a standalone checkbox field, I've been using this code:

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


But further to this post, I'm now using a checkbox group in the search form instead, and there are 4 checkboxes within this checkbox group field. I have tried using the same conditional as above to get the checked state, but it doesn't seem to be working.

My code is below, and I wondered if you've got any ideas where I'm going wrong here?

 
{exp:low_search:form collection="ls_event_search" search_mode="all" result_page="/directory/advanced-search" secure="no" query="{segment_3}"}

<label><input type="checkbox" name="search:cf_event_opening_times[]" value="Thursday"{if low_search_search:cf_event_opening_times == "Thursday"} checked="checked"{/if} /> Thursday</label>

<label><input type="checkbox" name="search:cf_event_opening_times[]" value="Friday"{if low_search_search:cf_event_opening_times == "Friday"} checked="checked"{/if} /> Friday</label>

<label><input type="checkbox" name="search:cf_event_opening_times[]" value="Saturday"{if low_search_search:cf_event_opening_times == "Saturday"} checked="checked"{/if} /> Saturday</label>

<label><input type="checkbox" name="search:cf_event_opening_times[]" value="Sunday"{if low_search_search:cf_event_opening_times == "Sunday"} checked="checked"{/if} /> Sunday</label>

<input name="require_all" type="hidden" value="">

<p><input type="submit" value="Search" class="button" />

{/exp:low_search:form}


I've also tried using a conditional in this format:

 
<label><input type="checkbox" name="search:cf_event_opening_times_search[]" value="Sunday"{if Sunday IN ({low_search_search:cf_event_opening_times_search[]})} checked="checked"{/if} />&nbsp;Sunday</label>


But I found that this format gave a selected state at all times, whether the checkbox was checked or not.

When I check each of the 4 days, the following variable ({low_search_search:cf_event_opening_times_search}) outputs: Thursday|Friday|Saturday|Sunday.

Thanks,

Stephen

Replies

  1. Low 1 Jul 2013 13:36

    Use something like this:

    {if "Sunday" IN ({low_search_search:cf_event_opening_times_search})}

  2. Stephen 1 Jul 2013 13:53

    Thanks Low, that did the trick! :-)