We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34022 ☆ A M B ☆
    • 91 Posts
    I would really appreciate if someone could help me on this; it’s my first post on the MODx board smiley.

    I am trying to create a simple advanced search box with options to search either in the Page Title or by keyword (all content fields). I tried going to the demo site to see the examples, but the links to the config files seem to be down. I also don’t want to mess with the Ajax Search snippet itself or put my own PHP code in because I want to keep it easily upgradeable.

    Here is what I have so far:

    AjaxSearch Call:
    [!AjaxSearch? &ajaxSearch=`1` &clearDefault=`1` &advSearch=`allwords` &showIntro=`0` &addJscript=`0` &jscript=`mootools2` &ajaxMax=`3` &pagingType=`1` &landingPage=`2297` &moreResultsPage=`2297` &asLog=`1:1:500` &parents=`176` &tplInput=`search_layout_advanced` &config=`product` !]


    AjaxSearch input template (search_layout_advanced)
    [+as.showInputForm:is=`1`:then=`
    <form id="[+as.formId+]" action="[+as.formAction+]" method="post">
        <fieldset class="inputAS">[+as.showAsId:is=`1`:then=`<input type="hidden" name="[+as.asName+]" value="[+as.asId+]" />`+]
        <input type="hidden" name="advsearch" value="[+as.advSearch+]" />
        <input type="hidden" name="searchField" value="content" />
        <div class="radio">
          <input id="pagetitle" type="radio" name="searchField" value="content:pagetitle" /><label for="pagetitle">Search by Page Title</label>
          <input id="content" type="radio" name="searchField" value="content" /><label for="content">Search by Keyword</label>
        </div>
        <div id="[+as.radioId+]">
          <input id="[+as.onewordId+]" type="radio" name="advsearch" value="[+as.oneword+]" [+as.onewordChecked+] /><label for="[+as.onewordId+]">[+as.onewordText+]</label>
          <input id="[+as.allwordsId+]" type="radio" name="advsearch" value="[+as.allwords+]" [+as.allwordsChecked+] /><label for="[+as.allwordsId+]">[+as.allwordsText+]</label>
          <input id="[+as.exactphraseId+]" type="radio" name="advsearch" value="[+as.exactphrase+]" [+as.exactphraseChecked+] /><label for="[+as.exactphraseId+]">[+as.exactphraseText+]</label>
          <input id="[+as.nowordsId+]" type="radio" name="advsearch" value="[+as.nowords+]" [+as.nowordsChecked+] /><label for="[+as.nowordsId+]">[+as.nowordsText+]</label>
        </div>
        <label>
          <input id="[+as.inputId+]"class="cleardefault" type="text" name="search" value="[+as.inputValue+]"[+as.inputOptions+] />
        </label>
        [+as.liveSearch:is=`0`:then=`
            <label>
                <input id="[+as.submitId+]" type="submit" name="sub" value="[+as.submitText+]" />
            </label>
        `+]    </fieldset>
    </form>
    `+]
    [+as.showIntro:is=`1`:then=`
    <p class="ajaxSearch_intro" id="ajaxSearch_intro">[+as.introMessage+]</p>
    `+]


    And, finally, my config file (product.config.php):
    <?php
    /*
     *  categConfig :   To define the display of categories (output)
     *  Add a category as a switch item. 'uncategorized' item describe the results outside of any category
     *  Add a switch for a new site. The default site is named 'defsite'.
     *  Allowed config parameters : grpLabel, tplResult, tplAjaxResult, display, extract, rank ...
     */
    function searchField($field){
    	$config = array();
    	$site = strtolower($field);
    	switch($field){
    		case 'pagetitle':
    			$config['whereSearch'] = 'content:pagetitle';
    			break;
    		case 'allfields':
    			$config['whereSearch'] = 'content:longtitle';
    			break;
    		default:
    			$config['whereSearch'] = 'content:pagetitle';
    	}
    	return $config;
    }
    ?>


    I’ve also tried it several other ways (having just functions as radio input values and creating two different functions, one for each option), but nothing seems to work. No matter what I do, I may as well pretend the radio buttons are not there. The search still works - it’s just not filtered.

    It’s hard because I don’t have the example config files to follow off of (except ones to create categories in the output). I would really appreciate it if someone could answer as fast as possible, as the search needs to be up as fast as possible.

    Thank you!

    - GELO
      WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area