We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32756
    • 25 Posts
    Hi,

    I’m working on a project where I need to search on multiple fields with multiple input form fields to search an events database.

    I need to have blanks for:


    • keyword: (this is straightforward) that searches "resource content" within the documents
    • city: searches for text within a specific TV called "city"
    • date start: each item has a TV with an event start; this field restricts results with event starts after value here
    • date end: much like "date start" but restricts results to events that have an event end before value here.

    I cannot find anything in the docs or online that explains how to use AjaxSearch or anything else for that matter to achieve what I need.

    Any help or advice would be appreciated.

    Thanks.
      • 32756
      • 25 Posts
      I have crossed this one off my to-do list. Instead of using AjaxSearch, I created a snippet that creates multiple ditto filters. Works great.

      If anyone needs details, let me know.
        • 36575
        • 104 Posts
        HI, I would love details! I want to do something similar for an Events List (it’s currently small), here: http://www.highbeam.co.nz/event-calendar/ and also another project than I am scoping now.

        Thanks, Rachel
          • 32756
          • 25 Posts
          Hi Rachel,

          Basically, I created a page with a form with multiple fields, and the form action was to the search results page. The search results page contains a call to the snippet that displays the results.

          <p>[!SearchEvents? !]</p>


          The snippet itself is fairly simple, and gets the data passed to it like so:

            $kw = clean ( $_REQUEST["keywords"] );
            $ct = clean ( $_REQUEST["city"] );
          // and so on...
          


          I have a php function in the code to sanitize the input:

          // clean data function
            function clean ($data) {
              // cleans data from user input
              $cleanoutput = mysql_escape_string (htmlentities( stripslashes($data) ) );
              return $cleanoutput;
            }
          


          Then later in the snippet, I have code blocks that look like this:

            // process city if exists
            if( !empty($ct) ) {
          	if ( empty($filter) ) {
          		$filter .= "";
          	}
          	else {
          		$filter .= "|";
          	}
          	$filter .= "EventCity," . $ct . ",9";
            }
          // and so on for each of the others
          


          And then finally, I have ditto do the search with the built-up filter from above.

            // run ditto
            return $modx->runSnippet(
          	'Ditto',
          	array(
          		'parents'=>'150',
          		'tpl'=>'SearchEvents_tpl',
          		'depth'=>'0',
          		'filter'=>$filter,
          		'noResults'=>'no results',
          		'seeThruUnpub'=>'1',
          		'caseSensitive'=>'0',
          		)
          	);
          


          There you go, Rachel. This should get you up and running.

          Let me know if you have any questions.

          Cheers!