SETTING UP BASIC SEARCHES - Sep 4th, 2022


Here’s some basic code that you can use to set up a simple search box on the list page of a multi-record editor to
return only those records that match your search criteria. There's also a cancel search form. Style the forms to match
your needs.

***If 'allowSearch' => is in your load records call at the top of your viewer, make sure that its set to true ***



<form action="" type="post">
<input type="text" name="your_field_name_keyword" id="search" placeholder="Enter A Name To Search For - Partial
Names OK" value="<?php echo htmlencode(@$_REQUEST['your_field_name_keyword']); ?>" size="60" />
<input type="submit" value="Start Your Search" />
</form>

<form type="post" action="" >
<input type="submit" value="Cancel Search Filters - Show All Records">
</form>

Notice the “name” entry on the sample form above. It starts with the field in which you want to preform the search
(your_field_name) and is followed by a modifier that determines what type of search is to be performed (_your-criteria).

CMSB is set up to allow you to search by many criteria by changing ( _your-criteria) in the “name” entry to one of
these:

_match - an exact match
_keyword - will look for specific words or partial words
_prefix - starts with keyword (or letter)
_query - allows google-style query searches such as: +dog -cat "multi word phrase". Only records matching EVERY word or
quoted phrase are returned. Words or phrases that start with - mean "must not match". The + means "must match" Its
optional and not required.
_fieldname_empty Matches blank fields. Matches fields that are blank ("").
_min - A minimum value for numeric searches
_max - A maximum value for numeric searches
_year year number for date searches
_month - month number for date searches
_day - Day of month for date searches

So, let’s say you’ve set up a field called “fruit” that can contain one or more keywords, like Apple, Banana,
Pear, Orange.

Here’s the basic code that you would use to search for one of those.



<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="text" name="fruit_keyword" value="">
<input type="submit" name="submit" value="Search">
</form>



If the visitor entered Apple, Banana, Pear, or Orange, only those records that contained the keyword would be listed.

You could also change the form to include a drop down menu of choices instead of the text box like this:



<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">

<select name="fruit_keyword">
<option value="">Please Choose a Fruit</option>
<option value="Apple">Apple</option>
<option value="Banana">Banana</option>
<option value="Pear">Pear</option>
<option value="Orange">Orange</option>
</select>

<input type="submit" name="submit" value="Search">
</form>




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service