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.

Help with advanced search form

January 12, 2012 9:28am

Subscribe [2]
  • #1 / Jan 12, 2012 9:28am

    mjftrifecta

    3 posts

    I want to use the advanced search form for a job board and populate the categories from one channel only. I do not want to use the select option from an array of channels. I want to have one channel already selected. How would I change the code so that the user does not need to SELECT a channel in order to populate the categories field? I know it’s a simple change, but am having trouble.

    I am using the newest version of EE.

    Following is the code that is generated. I want to hide the channel option completely and have the category field populated with the categories associated with the channel. If the user adds or changes the categories, this would then be reflected in the form.

    Here is the current code.

    <form id="searchform" method="post" action="http://test.www.drbobnelson.com/"  >
    <div class='hiddenFields'>
    
    <input type="hidden" name="ACT" value="6" />
    <input type="hidden" name="XID" value="6de547148aac465917f1ca0dc1d96df72f16434f" />
    <input type="hidden" name="RES" value="" />
    <input type="hidden" name="meta" 
    
    value="YTo4OntzOjY6InN0YXR1cyI7czowOiIiO3M6NzoiY2hhbm5lbCI7czo2OiJwaG90b3MiO3M6OToic2VhcmNoX2luIj
    
    tzOjA6IiI7czo1OiJ3aGVyZSI7czozOiJhbGwiO3M6MTI6InNob3dfZXhwaXJlZCI7czowOiIiO3M6MTk6InNob3dfZnV0dXJ
    
    lX2VudHJpZXMiO2I6MDtzOjExOiJyZXN1bHRfcGFnZSI7czoyMToic2VhcmNoL3NlYXJjaF9yZXN1bHRzIjtzOjE1OiJub19y
    
    ZXN1bHRzX3BhZ2UiO3M6MTc6InNlYXJjaC9ub19yZXN1bHRzIjt9ZmNiZDU4MTY3Nzk4YTA1NjYxMGJkNTI0MGM1NmMxNjE=" 
    
    />
    <input type="hidden" name="site_id" value="1" />
    </div>
    
    [removed]
    //<![CDATA[
    
    var firstcategory = 1;
    var firststatus = 1;
    
    function changemenu(index)
    { 
     var categories = new Array();
     
     var i = firstcategory;
     var j = firststatus;
     
     var theSearchForm = false
     
     if (document.searchform)
     {
      theSearchForm = document.searchform;
     }
     else if (document.getElementById('searchform'))
     {
      theSearchForm = document.getElementById('searchform');
     }
     
     if (theSearchForm.elements['channel_id'])
     {
      var channel_obj = theSearchForm.elements['channel_id'];
     }
     else
     {
      var channel_obj = theSearchForm.elements['channel_id[]'];
     }
     
     var channels = channel_obj.options[index].value;
     
     var reset = 0;
    
     for (var g = 0; g < channel_obj.options.length; g++)
     {
      if (channel_obj.options[g].value != 'null' && 
       channel_obj.options[g].selected == true)
      {
       reset++;
      }
     } 
      
     with (theSearchForm.elements['cat_id[]'])
     {   
      if (channels == "7")
      { 
       categories[i] = new Option("-------", ""); i++; 
       categories[i] = new Option("Random Photos", "2"); i++; 
       categories[i] = new Option("Webinar Photos", "1"); i++; 
    
      } // END if channels
       
       
            
      if (reset > 1)
      {
        categories = new Array();
      }
    
      spaceString = eval("/!-!/g");
      
      with (theSearchForm.elements['cat_id[]'])
      {
       for (i = length-1; i >= firstcategory; i--)
        options[i] = null;
       
       for (i = firstcategory; i < categories.length; i++)
       {
        options[i] = categories[i];
        options[i].text = options[i].text.replace(spaceString, 
    
    String.fromCharCode(160));
       }
       
       options[0].selected = true;
      }
      
     }
    }
    
    //]]>
    [removed]
     
        
            <fieldset class="search">
           <input name="keywords" type="text" class="box" id="keywords" value="Search our site" 
     /> 
           
        
     <select id="channel_id" name='channel_id[]'>
                            <option value="null" selected="selected">Any Channel</option>
    
    <option value="7">Photos</option>
    
                    </select>
    
                 <select id="cat_id" name='cat_id[]'  class='multiselect' multiple='multiple'>
                         <option value='all' selected="selected">Any Category</option>
    
                 <select>
    </select>
    
    
    
                    </select>
    
            <button class="btn" title="Submit Search">Go</button>
            </fieldset>
    
       </form>

    I want PHOTOS to always be selected and have the categories field always populated with the categories associated with this option.

    Thanks for your help.

     

  • #2 / Jan 12, 2012 10:07am

    mjftrifecta

    3 posts

    I figured out how to do this. Please disregard this post!

  • #3 / Jan 12, 2012 10:23am

    glenndavisgroup

    436 posts

    Not sure if this is the right way of doing it but you can do something like this:

    {exp:search:advanced_form channel="photos" no_result_page="search/no_results" result_page="search/results" status="not closed" search_in="everywhere" id="frmSearch" name="frmSearch"}
    <input type="text" name="keywords" id="keywords" value="" />
    <div>{lang:categories}</div>
    <select name='cat_id[]' size='12'  class='multiselect' multiple='multiple'>
        <option value='all' selected="selected">{lang:any_category}</option>
    {exp:channel:categories channel="photos" show_empty="no"}
        <option value='{category_id}'>{category_name}</option>
    {/exp:channel:categories}</select>
    {/exp:search:advanced_form}

    I hope that helps.

    Mike

  • #4 / Jan 13, 2012 5:31pm

    Dan Decker

    7338 posts

    Hi mjftrifecta,

    I’m glad you were able to come to a solution! If you need anything else, just let us know in a new thread.

    Mike, thanks for you input and insight, as always!

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases