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 with drop-down and text fields

August 12, 2010 5:59pm

Subscribe [5]
  • #1 / Aug 12, 2010 5:59pm

    JenSkim

    197 posts

    I want an advanced search where the user can either enter keywords or choose a category from a drop-down menu. Code is below. I’m being prompted to enter a keyword when the field is left empty, “You did not submit a search term.”

    I see many people asking why this can’t be done. Why can’t this be done?

    Any suggestions to make this work?

    {exp:search:advanced_form result_page="resultspage" search_in="weblog" status="open" dynamic="off"}
    <input type="text" class="input" maxlength="100" size="40" name="keywords" style="width:90%;" />
    <select name="search_in">
    {exp:weblog:category_archive weblog="weblog" style="linear" show_empty="no" status="open"}
    {categories}
    <option value="{path=mypath}" >{category_name}</option>
    {/categories}
    {/exp:weblog:category_archive}
    </select>
    <input type='submit' value='Search' class='submit' />
    {/exp:search:advanced_form}
  • #2 / Aug 12, 2010 6:14pm

    I’m having the exact seem issue, on EE 2.1.

    Any insights?

  • #3 / Aug 12, 2010 6:18pm

    JenSkim

    197 posts

    Not yet… but I’m hoping the EE admins will have a solution soon.

  • #4 / Aug 13, 2010 3:11am

    John Henry Donovan

    12339 posts

    JenSkim,
    So what you really are looking for is a simple search form alongside a dropdown menu for categories. Not combined at all?

    You can create a category menu which will jump tot your category page like so

    <form name="catmenu" action="">
      <select name="selcat">
        <option value="">--Select Category--</option>
    {exp:weblog:categories weblog="yourweblog" style="linear" dynamic="off"}
        <option value="{path=weblog}">{category_name}</option>
    {/exp:weblog:categories}
      </select>
    </form>

    Does that help?

  • #5 / Oct 24, 2011 5:46pm

    artlab

    37 posts

    In my case at least, I am looking for a combined solution.
    On most web sites you can search by category and/or keyword.  If keyword is blank then you just search on the category.
    But if category is selected and keyword is not blank, you search on keyword AND category.
    Is there a solution to this without writing PHP code and SQL queries?

  • #6 / Oct 25, 2011 8:40pm

    Dan Decker

    7338 posts

    artlab,

    You can’t leave the keyword field blank, as the search will fail without it. You might be able to accomplish something similar if you use the category dropdown that John Henry describes, and in a separate area you could provide a category select menu that “filters” your keyword search:

    {exp:search:advanced_form result_page="search/results"}
    <select name='cat_id[]' size='12'  class='multiselect' multiple='multiple'>
     <option value='all' selected="selected">{lang:any_category}</option>
    </select>
    <input type="text" class="input" maxlength="100" size="40" name="keywords" />
    <input type="hidden" name="where" value="any" />
    <input type='submit' value='Search' class='submit' />
    {/exp:search:advanced_form}

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases