Searching multiple fields with one text field

6 posts by 3 authors in: Forums > CMS Builder
Last Post: May 22, 2018   (RSS)

By gversion - May 21, 2018

Hello,

Is it possible to set up one text input field to carry out a "fieldname_prefix" search on two database fields?

e.g.

<input type="text" class="form-control" id="search" name="keywords_keyword,product_prefix" placeholder="Search">

The above code only carries out the search on "product" fieldname. I also want the search to be carried out on the "keywords" field.

I wonder if I can put the fields I want to search in an <input> hidden tag...?

Thanks as always for the help!

Regards,

Greg

By Codee - May 21, 2018

Hi Greg,

there are several modes of using the search form - and at least one of them can be used for searching multiple fields in records. One of the methods is a query through text fields, and it's important that the last field to be searched has "_query" addended to it.  I currently use one on a site (and it works well) that is similar to this

<span class="searchform">Type your search term in the box and click "Search Inventory". </span>
<form method="POST" action="/yourresultspage.php">
<input type="text" name="stock_number,year,additional_comments,license,make,model,title_query" value="">
<center>
<input type="submit" name="submit" value="Search Inventory">
</center>
</form>

By gversion - May 21, 2018

Hi equinox

Thanks for the reply - that's really helpful.

According to the below link, the 'query' search type will return, "Only records matching EVERY word or quoted phrase...":

https://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

Is it possible to carry out different search types per field using one text input field? Or do they all need to use the same search type (e.g. "_query" from your example)? 

Thanks,

Greg

By leo - May 22, 2018

Hi Greg,

With html input field you can only define one search type (_prefix, _query) since that is the input field name. If you want to use the exact same input for other search types you can do it by making a copy of the $_REQUEST[] variable with the name you want to search before the getRecords() gets the records from the database. Example: $_REQUEST['field_query'] = $_REQUEST['field_prefix'].

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

By gversion - May 22, 2018

Thanks, Leo!