We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37015
    • 21 Posts
    I've just installed the SimpleSearch add-on and would like to customize the search form to fit with the style of my site.

    Here is my call to show the form:

    <div class="topbar">[[!SimpleSearchForm? &tpl='MySimpleSearch' &landing='213' ]]</div>


    The tpl chunk code: (this is currently just the default one provided in the documentation.

    <form id="my_id" action="[[~[[+landing:default=`[[*id]]`]]]]" method="[[+method:default=`get`]]">
            <input id="searchField" class="my_class" type="text" name="my_custom_search_field" value="[[+searchValue:default=`Search the site`]]"/>
            <input id="searchIcon" class="utilityButton" type="image" alt="Search" src="/assets/templates/my/images/searchButton.png">
            <input type="hidden" name="id" value="[[+landing:default=[[*id]]]]" />
    </form>


    The snippet SimpleSearchForm:
    require_once $modx->getOption('sisea.core_path',null,$modx->getOption('core_path').'components/simplesearch/').'model/simplesearch/simplesearch.class.php';
    $search = new SimpleSearch($modx,$scriptProperties);
    
    /* setup default options */
    $scriptProperties = array_merge(array(
      'tpl' => 'SearchForm'
      'method' => 'get',
      'searchIndex' => 'search',
      'toPlaceholder' => false,
      'landing' => $modx->resource->get('id'),
    ), $scriptProperties);
    
    if (empty($scriptProperties['landing'])) {
      $scriptProperties['landing'] = $modx->resource->get('id');
    }
    
    /* if get value already exists, set it as default */
    $searchValue = isset($_REQUEST[$scriptProperties['searchIndex']]) ? $_REQUEST[$scriptProperties['searchIndex']] : '';
    $searchValues = explode(' ', $searchValue);
    array_map(array($modx, 'sanitizeString'), $searchValues);
    $searchValue = implode(' ', $searchValues);
    $placeholders = array(
        'method' => $scriptProperties['method'],
        'landing' => $scriptProperties['landing'],
        'searchValue' => strip_tags(str_replace(array('[',']','"',"'"),array('[',']','"','&apos;'),$searchValue)),
        'searchIndex' => $scriptProperties['searchIndex'],
    );
    
    $output = $search->getChunk($scriptProperties['tpl'],$placeholders);
    return $search->output($output,$scriptProperties['toPlaceholder']);


    With that code - no search box appears. Yet with the &tpl argument removed it works again.

    Am I overlooking something here or is there something else I need to do?

    Thanks
    Dan
      • 3749
      • 24,544 Posts
      Try this:

      Edit the page with the snippet tag and copy the exact name of your Tpl chunk. Then, edit that Tpl chunk. Highlight the name of the chunk (be sure you capture any leading or trailing spaces) and paste the name you copied from the tag. Save the chunk.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 18367
        • 834 Posts
        Quote from: BobRay at Apr 27, 2014, 07:26 PM
        Try this:

        Edit the page with the snippet tag and copy the exact name of your Tpl chunk. Then, edit that Tpl chunk. Highlight the name of the chunk (be sure you capture any leading or trailing spaces) and paste the name you copied from the tag. Save the chunk.


        But isn't that what he's already done? I only ask 'cos I'm having the same problem.
          Content Creator and Copywriter
          • 3749
          • 24,544 Posts
          Doh. I just wrote out a long answer for you but, just before posting it, I took another look at the OP's snippet tag. The problem is that it uses single quotes rather than back-ticks.

          A missing question mark after the snippet name in the tag, or a missing ampersand (&) can also cause that problem.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting