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 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 Codee - May 22, 2018

Hi Greg,

What Leo said...

;-)

By gversion - May 22, 2018

Thanks, Leo!