The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« Configuring Search for One or More Weblogs | Up | Customize the Default Search Template »

Chapter 10: Search

Creating a Search Form

Problem

Your system is configured to enable search. Now you want to make it available to readers of your weblog.

Solution

Add an HTML form to your template that submits a "search" field to the Movable Type Search script.

Discussion

Like any CGI application, we insert an HTML form into a layout to make those services accessible to readers. Here is a basic form that may be used:

 <form method="get" action="<$MTCGIPath$><$MTSearchScript$>">
 <label for="search" accesskey="4">Search this  site:</label><br />
 <input id="search" name="search" size="20" /><br />
 <input type="submit" value="Search" />
 </form>

This form requires one parameter: search, (default values are used for the rest) and passes it to the search script.

Most of the bells-and-whistles in this form may not be overridden by the reader. Here is an HTML form that exposes those options to the reader:

 <form method="post" action="<$MTCGIPath$><$MTSearchScript$>">
 <input size="30" name="search" value="<$MTSearchString$>" />
 <input type="submit" value="Search" /><br />
 <input type="checkbox" name="CaseSearch" /> Match case 
 <input type="checkbox" name="RegexSearch" /> Regex search<br />
 <b>Search:</b>
 <input type="radio" name="SearchElement" value="entries" /> Entries 
 <input type="radio" name="SearchElement" value="comments" /> Comments 
 <input type="radio" name="SearchElement" value="both" /> Both <br />
 <b>Sort By:</b>
 <select name="SearchSortBy">
 <option value="created_on">Authored On Date</option>
 <option value="title">Title</option>
 </select><br />
 <b>Sort Order:</b>
 <select name="ResultDisplay">
 <option value="ascend">Ascending</option>
 <option value="descend">Descending</option>
 </select><br />
 <b>Exclude Weblogs:</b>
 <MTBlogs>
 <input type="checkbox" name="ExcludeBlogs" value="<$MTBlogID$>" /> <$MTBlogName$>
 </MTBlogs><br />
 <b>Search entries from:</b>
 <select name="SearchCutoff">
 <option value="9999999">the beginning</option>
 <option value="7">one week back</option>
 <option value="14">two weeks back</option>
 <option value="30">one month back</option>
 <option value="60">two months back</option>
 <option value="90">three months back</option>
 <option value="365">one year back</option>
 </select><br />
 <b>Results per weblog:</b>
 <select name="MaxResults">
 <option value="5">5</option>
 <option value="10">10</option>
 <option value="25">25</option>
 <option value="50">50</option>
 <option value="100">100</option>
 <option value="9999999">All<code>/option</code>
 </select>
 </form>

This form exposes all of the options to the reader for tailoring to their own liking. Optionally, these parameters can be passed to the search script via hidden input tags. A benefit of using this approach is that configured options are set only for the reader and won't alter parameters in the MT configuration file that may be used by the search elsewhere in the site.

Keep in mind, that depending upon the system's contents, it may not be advisable for all parameters to be overridden through HTML forms and query parameters.

If you've created an Alternate Search Template, and want to tell Movable Type which template to use when outputting the search results pages, you will use a hidden form input with a name of 'Template.' For example, to use the "play" template instead of the default, insert this hidden form input into the form above:

 <input type="hidden" name="Template" value="play" />

If you're not using Alternate Search Templates, you may still wish to "Customize the Default Search Template" which is used to display the results.

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated; but please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form. If you have a technical question or problem, visit Movable Type Support.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.