ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic parameters and wildcard searches?

October 17, 2012 3:18am

Subscribe [1]
  • #1 / Oct 17, 2012 3:18am

    Dan Storm

    70 posts

    I’m currently in the process of trying to filter some channel entries by using dynamic parameters.

    My current template looks like this:

    <form method="post" action="" id="filter" class="filter">
         <div class="row">
          <select name="search:country">
           <option value="IS_EMPTY|not IS_EMPTY">Choose country</option>
           {exp:query sql="SELECT distinct field_id_90 FROM exp_channel_data where field_id_90 != ''"}
           <option value="{field_id_90}"<?php if($this->EE->input->post('search:country') == "{field_id_90}"): ?> selected="selected"<?php endif; ?>>{field_id_90}</option>
           {/exp:query}           
          </select>
          <select name="search:language">
           <option value="IS_EMPTY|not IS_EMPTY">Choose language</option>
           {exp:query sql="SELECT distinct field_id_89 FROM exp_channel_data where field_id_89 != ''"}
           <option value="{field_id_89}"<?php if($this->EE->input->post('search:language') == "{field_id_89}"): ?> selected="selected"<?php endif; ?>>{field_id_89}</option>
           {/exp:query}           
          </select>
         </div>
         <div class="row">
          <select>
           <option>Choose month</option>
           <option>2</option>
           <option>3</option>
           <option>4</option>
           <option>5</option>
          </select>
          <select name="search:city">
           <option value="IS_EMPTY|not IS_EMPTY">Choose city</option>
           {exp:query sql="SELECT distinct field_id_88 FROM exp_channel_data where field_id_88 != ''"}
           <option value="{field_id_88}"<?php if($this->EE->input->post('search:city') == "{field_id_88}"): ?> selected="selected"<?php endif; ?>>{field_id_88}</option>
           {/exp:query}           
          </select>
          
         </div>
    
         
         </form>
    
         {exp:channel:entries channel="events" show-future-entries="yes" dynamic_parameters="search:country|search:city|search:language"}
          Showing my entries…
         {/exp:channel:entries}

    Now, this issue is that it’s apparently not possible to provide an empty value nor my attempt with “IS_EMPTY|not IS_EMPTY” to show channel entries when only one filtering option is selected.

    The current way it works is that we need to fill out every filter option to get any results.
    Can this be done in another way?

    And a bonus question - can I use the dynamic parameters to filter by a certain month?

  • #2 / Oct 17, 2012 12:17pm

    Dan Decker

    7338 posts

    Hi Dan,

    Wow - this is a pretty interesting scenario!

    Have you used the “=” as part of the name attribute and only one default option:

    <select name="search:country=">
    
    ... and ...
    
    <option value="not IS_EMPTY">Choose country</option>

    And a bonus question - can I use the dynamic parameters to filter by a certain month?

    Indeed. Set it like you would any other dynamic parameter:

    <select name="month">
    
    ... and ...
    
    <option value="12">December</option>

    Cheers,

  • #3 / Oct 18, 2012 7:24am

    Dan Storm

    70 posts

    Hi,

    Wow - this is a pretty interesting scenario!

    Have you used the “=” as part of the name attribute and only one default option:

    <select name="search:country=">
    
    ... and ...
    
    <option value="not IS_EMPTY">Choose country</option>

    The attempt resulted in getting error messages about non allowed characters and this is probably casued by using the “=” in the input names.

    But still, this would require that the field is actually has a value, wouldn’t it?

    And a bonus question - can I use the dynamic parameters to filter by a certain month?

    Indeed. Set it like you would any other dynamic parameter:

    <select name="month">
    
    ... and ...
    
    <option value="12">December</option>

    It’s just so obvious that I actually feel silly now…

  • #4 / Oct 18, 2012 4:35pm

    Dan Decker

    7338 posts

    Hi Dan,

    But still, this would require that the field is actually has a value, wouldn’t it?

    Honestly, I just picked one of your piped options for illustration - not knowing which condition you would want to check for:

    <option value="IS_EMPTY">Choose country</option>

    Would be just as valid, only opposite. The important bit is to not have conflicting piped options as your default. Since “IS_EMPTY|not IS_EMPTY” would be passed when the user makes no choice, they would actually conflict on the other side. Make sense?

    Pick one of those to be your “default” - and that would be based on what results you want the user to see if they chose nothing in the dropdown.

    ~

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases