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.

Advanced search using dynamic dropdowns

August 13, 2012 4:16pm

Subscribe [1]
  • #1 / Aug 13, 2012 4:16pm

    aidan1234

    19 posts

    Hi guys,

    I have a form which contains a simple keyword text field search, just follows the documentation on the site, here is the main exerpt

    {exp:search:advanced_form result_page="search/results"}
    <table cellpadding='4' cellspacing='6' border='0' width='100%'>
    <tr>
    <td>
    <fieldset class="fieldset">
    <legend>{lang:search_by_keyword}</legend>
    
    <input type="text" class="input" maxlength="100" size="40" name="keywords" />
    
    </fieldset>
    </td>
    </tr>
    </table>
    <div class='searchSubmit'>
    <input type='submit' value='Search' class='submit' />
    </div>
    
    {/exp:search:advanced_form}

    Code works fine but I now want to replace the text field with a dynamic dropdown of people who work for a company. The options in the dropdown are driven by channel entries

    {exp:search:advanced_form result_page="search/results"}
    <table cellpadding='4' cellspacing='6' border='0' width='100%'>
    <tr>
    <td>
    <fieldset class="fieldset">
    
    <div class="default">
    <select id="search4">
    <option>By Name</option>
    {exp:channel:entries channel="people" orderby="title" sort="asc" validate="true" dynamic="no"}
    <option value="{title}"><a href="http://{page_uri}">{title}</a></option>
    {/exp:channel:entries} 
    </select>
    </div>
    
    </fieldset>
    </td>
    </tr>
    </table>
    <div class='searchSubmit'>
    <input type='submit' value='Search' class='submit' />
    </div>
    
    {/exp:search:advanced_form}

    The dropdown is populated with the list of people but when you try search, you get an error stating

    You did not submit a search term

    Any suggestions as to how I need to tweak this code to allow me submit a valid search for the person selected from the dropdown?

    Thanks

    Aidan

  • #2 / Aug 14, 2012 5:17pm

    Dan Decker

    7338 posts

    Hi Aidan,

    Sure thing!

    You need to name the select “keywords” like so:

    <select id="search4" name="keywords">
    <option>By Name</option>
    {exp:channel:entries channel="people" orderby="title" sort="asc" validate="true" dynamic="no"}
    <option value="{title}"><a href="http://{page_uri}">{title}</a></option>
    {/exp:channel:entries} 
    </select>

    That way you will submit the value of “option” as a “keyword” to be searched. Otherwise ExpressionEngine has no idea what you want to search for.

    Let me know if that works out OK.

    Cheers,

  • #3 / Aug 14, 2012 6:32pm

    aidan1234

    19 posts

    Thanks Dan,

    That worked perfect. I suppose there is always the follow-on question!

    There is also a requirement for a combined search page. The client would like to have a combined keyword text field and a dynamic dropdown search - would that be possible?

    To put it in context, you would have a normal text field plus a dropdown with the main divisions in the company (driven by channel entries) so for example, you want to run a combined search for the keyword “services” in the “facilities” division of the company.

    If I set the code like follows:

    {exp:search:advanced_form result_page="search/results"}
    <table cellpadding='4' cellspacing='6' border='0' width='100%'>
    <tr>
    <td>
    <fieldset class="fieldset">
    
    <div class="default"><input type="text" class="input" maxlength="100" size="40" name="keywords" /></div>
    
    <div class="default">
    <select id="search4">
    <option>By Division</option>
    {exp:channel:entries channel="divisions" orderby="title" sort="asc" validate="true" dynamic="no"}
    <option value="{title}"><a href="http://{page_uri}">{title}</a></option>
    {/exp:channel:entries} 
    </select>
    </div>
    
    </fieldset>
    </td>
    </tr>
    </table>
    <div class='searchSubmit'>
    <input type='submit' value='Search' class='submit' />
    </div>
    
    {/exp:search:advanced_form}

    I tried this code and it picked up on the keyword value but not the dropdown selection.

    I assume it can only have one field with the value “keywords”?

    Thanks

    Aidan

     

  • #4 / Aug 15, 2012 4:36pm

    Dan Decker

    7338 posts

    Hi Aidan,

    You can limit by channels using this code in your form:

    <select id="channel_id" name='channel_id[]' class='multiselect' size='12' multiple='multiple'>
                            {channel_names}
                    </select>

    That builds a multislect to pick your channel to limit the keyword to.

    Does that help?

    Cheers,

  • #5 / Aug 16, 2012 3:48am

    aidan1234

    19 posts

    Thanks Dan,

    That code snippet works but not quite what I was looking for.

    I have a channel called “Divisions” and I have a number of channel entries for this channel. They are called Sales, Technical, HR etc. Its all the high level divisions with the company.
    I then have a standard keyword text field search. So I would like to run a combined search that searches for a specific “keyword” in a particular division of the company.

    Thanks

    Aidan

  • #6 / Aug 17, 2012 1:41pm

    Dan Decker

    7338 posts

    Ahhh - OK - So you really want to limit the keyword down to an entry level, correct?

    The Search Module doesn’t support that fine-grained. The best you could do would be to limit the keywords to the Divisions channel.

    Searching within an entry would be something perhaps jQuery/JavaScript would be keen at. How large/long are the division focused entries?

    Cheers,

  • #7 / Aug 19, 2012 12:32pm

    aidan1234

    19 posts

    Hi Dan,

    Tks for the response. I am going to try Solspace’s Super Search to see if it allows me achieve the combined search I need.

    Tks

    Aidan

  • #8 / Aug 21, 2012 11:21am

    Dan Decker

    7338 posts

    Hi Aidan,

    Best of luck to you. As far as I know, Super Search and Low Search both have the same limitation as the included Search module: you can’t specify a particular entry to search within. They all filter down to the channel level, once in the channel, all entries in that channel will be searched.

    That was the reason I suggested an “in page” search solution - the search facilities available to ExpressionEngine can’t be filtered to the entry level.

    Is there anything else I can assist you with?

    ~

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

ExpressionEngine News!

#eecms, #events, #releases