2

I am looking to do a search of a few Zoo Visitor fields that are comprised of checkboxes. This was something I was working on a few months ago and I picked this project back up this week. I am having two different issues and I'm not sure if they are Zoo Visitor or Low Search issues so I figured I would post here to start.

The first issue has to do with the checkboxes themselves. I have three checkbox fields with anywhere from 10 to 50 options. Each option is listed on its own line as specified in "Multi-Select Options" within the channel field settings. A few of the options have commas in them and I'm not sure if that's an issue.

When I go to display these fields within my search, the checkbox fields all behave in very strange ways. All the fields in the low search form follow the same format every time:

<fieldset>
  <legend>Fieldname</legend>
  <div>
    <span class="label"></span>
    <div class="group">
        {exp:channel:entries 
          site="default_site" 
          channel="zoo_visitor"  
          status="not closed" 
          disable="categories|pagination"
        }

        {mbr_fieldname}
          <input type="checkbox" name="{item}" value="" /> {item}<br /><br />
        {/mbr_fieldname}
        {/exp:channel:entries}
    </div>
  </div>
</fieldset>

For two of these fields, some of the checkboxes being displayed have multiple values combined into one value. That is, instead of there being two separate checkboxes for Value 1 and Value 2, one checkbox will contain BOTH Value 1 and Value 2 together. Another one of these fields has multiples of the same value wjthin the list. For example, Value 3 might show up twice for no apparent reason. These values are also not in the order listed when I created the field. I even checked in the database and all the data looks to match what I entered properly the first time. To test this issue further, I created a new checkbox field this evening called testcheckboxes. When I tried to display this new field like so:

        {exp:channel:entries 
          site="default_site" 
          channel="zoo_visitor"  
          status="not closed" 
          disable="categories|pagination"
        }

        {testcheckboxes}
          <input type="checkbox" name="{item}" value="" /> {item}<br /><br />
        {/testcheckboxes}
        {/exp:channel:entries}

No entries show up whatsoever.

The second issue has to do with the checkboxes that DO show up. If I try to check off any of these boxes and search, no member results are found even if I know a particular member has these boxes checked off. The checkbox fields are marked as searchable and the results page has a status="not closed".

I'm hoping to be able to unravel this problem soon but I'm really not sure where to go from here. Any help would be greatly appreciated. Thank you.

9

Generating the checkboxes

Take a good look at what you're trying to achieve, and what you're actually doing. You want a list of checkboxes that contains all options for a given Checkboxes field. So, for example, say your mbr_fieldname contains 3 checkboxes for primary colors. In that field's settings, you've added the three colors in the Multi-Select Options setting, so in your publish form, that would look like this:

[ ] Blue
[ ] Red
[ ] Yellow

Each entry (member, in your case) is assigned one or more colors, which you can loop through using the {mbr_fieldname}{/mbr_fieldname} variable pair. So, this code:

{exp:channel:entries ... }
    {mbr_fieldname}
        {item}
    {/mbr_fieldname}
{/exp:channel:entries}

...will loop through each entry and display each color for that entry. It will not display Blue Red Yellow, which is what you would be after. Just add a {title} to it, and you'll see.

So, if you just want to display the options rather than the actual entry values, don't use the Entries tag. Instead, either hard-code the options in your template, or use Low Options, which was created specifically for that purpose. With that, you can generate the list of checkboxes like this:

{exp:low_options:mbr_fieldname}
    {options}
        {option:value}
    {/options}
{/exp:low_options:mbr_fieldname}

Which brings me nicely to your second issue: the filter that doesn't work.

Filtering entries based on those checkboxes

You want to only display entries based on the option that was checked. How would you achieve this without a form or Low Search, but just using the channel:entries tag? You'd use the search:my_field parameter, like so:

{exp:channel:entries channel="zoo_visitor" search:mbr_fieldname="Red" ... }

That means you're going to have to use Low Search's Field Search filter. And as per How Parameters Work in Low Search, that means using an input field with name="search:mbr_fieldname".

However, the Checkboxes field allows multiple values, so you want to be able to include multiple values, too. Not a problem, Low Search caters for that, too. So, you end up with this (using proper <label>s instead of the <br>s):

{exp:low_options:mbr_fieldname}
    {options}
        <label>
            <input type="checkbox" name="search:mbr_fieldname[]" value="{option:value}">
            {option:label}
        </label>
    {/options}
{/exp:low_options:mbr_fieldname}

Note the [] in the name attribute and actually setting the value attribute, too.

  • 1
    Thank you, Low. I'm going to digest this to make sure I fully understand but it already makes a lot of sense to me. Thank you very much for your help. As a relative newcomer to EE, this community is an absolute lifesaver. I hope to be able to answer someone else's question in the future! – NPI Jun 27 '14 at 15:30
  • Low, you mention that Low Options is a good way to display the options rather than the actual entry values. What if I DID want to display the entry values? (Say, for an "Edit Profile" page) Could I use Low Options for this or would I need to find another solution? – NPI Jun 30 '14 at 2:38
  • 1
    You should probably use Channel Form and its method of displaying fields to do that. – Low Jun 30 '14 at 7:20

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.