Multiple Search Form

11 posts by 5 authors in: Forums > CMS Builder
Last Post: October 12, 2010   (RSS)

By (Deleted User) - September 8, 2009

Hi,

All my CMS Builder sites until now need no search FORMS. The site was so organized that each section had the search built into the URL to filter out the results.

I now need to create a search form to search more than one field. Or as some call it, an “Advance Search”. I already created one form to do a simple search. It searches the name field only and it works very good.

Can somebody post some basic code for a search form that will search a few fields? Right now the fields I need to search for are as follows:
  • name
  • city
  • state
  • country

Re: [RapidWeb] Multiple Search Form

By Chris - September 8, 2009

Hi RapidWeb,

Do you need to search multiple fields or multiple tables/sections?

If you only need to search multiple fields, here's a simple solution for you. Replace the STEP 1 code from a List page viewer with the following:

require_once "C:/wamp/www/cmsbuilder_1_34_build1/cmsAdmin/lib/viewer_functions.php";

$fieldsToSearch = array(
'name',
'city',
'state',
'country',

);

// if the visitor supplied a search string, construct a where clause to search all the fields we want to search
$search_string = @$_REQUEST['q'];
if ($search_string) {
$searchClauses = array();
foreach ($fieldsToSearch as $field) {
array_push($searchClauses, "$field LIKE '%" . mysql_escape($search_string) . "%'");
}
$where = join(' OR ', $searchClauses);
}
// if the visitor did not supply a search string, return all records
else {
$where = '1';
}


list($records,) = getRecords(array(
'tableName' => 'listings',
'where' => $where,
));


replacing the code in red with your own information.

I hope this helps. Please let us know if you have any questions or comments.
All the best,
Chris

Re: [chris] Multiple Search Form

By (Deleted User) - September 8, 2009

[font "Times New Roman"]Thanks for the reply. Not sure if I understand what I need to do.

[font "Times New Roman"]

[font "Times New Roman"]I have a search box inside a form on a regular HTML page. It is the simple search as described in your documentation here:

[url "http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html"][font "Times New Roman"]http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html[/#800080][/url]

Custom Search Forms

You can create search forms by naming the fields after what you want them to search. Here is a simple search form that searches the "title" field for a keyword.

<form method="POST" action="/path/to/your/listViewer.php">

<input type="text" name="title_keyword" value="">

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

</form>

[font "Times New Roman"]

[font "Times New Roman"]The test form is on my page here:

[url "http://www.koshertravelinfo.com/minyan/search_minyan.html"][font "Times New Roman"]http://www.koshertravelinfo.com/minyan/search_minyan.html[/#800080][/url]

[font "Times New Roman"]It searches a field called “minyan_name”.

[font "Times New Roman"]

[font "Times New Roman"]Here is what I am trying to do. I want the site visitor to be able to search more than one field. The form should have more than one text entry box. Like our old advance search form we used with “Listing Manager”. Sample here:

[url "http://www.koshertravelinfo.com/davendb/exec/search.cgi"][font "Times New Roman"]http://www.koshertravelinfo.com/davendb/exec/search.cgi[/#800080][/url]

[font "Times New Roman"]

Re: [RapidWeb] Multiple Search Form

By Chris - September 8, 2009

Ahh, it seems we both misunderstood you. You won't need to change minyan.php at all, just add some more fields to the form on your search_minyan.html page. You already have this one:

<input type="text" name="minyan_name_keyword" value="">

just add some more...

Minyan Name: <input type="text" name="minyan_name_keyword" /><br />
City: <input type="text" name="city_keyword" /><br />
State: <input type="text" name="state_keyword" /><br />
Country: <input type="text" name="country_keyword" /><br />
Content: <input type="text" name="content_keyword" /><br />


You can add as many as you want, just make sure to use your own field names (shown in red.)

Please let us know if you have any more questions. :)
All the best,
Chris

Re: [chris] Multiple Search Form

By Codee - October 11, 2010

so does this code go on the page with a search form or on the list page viewer? Does this page understand any form code posted to it?

Re: [equinox69] Multiple Search Form

By Chris - October 12, 2010

Hi equinox69,

The code in my last post would go in a search form on any page. The search form looks at all the form fields posted to it and, if they match up with field names, will use them to filter search results.

That is, unless you set disable 'allowSearch' in your getRecords() options.

Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Multiple Search Form

By Codee - October 12, 2010

Hi Chris,

I think I'm referring to the post before the last one with regards to this code:

require_once "C:/wamp/www/cmsbuilder_1_34_build1/cmsAdmin/lib/viewer_functions.php"; $fieldsToSearch = array( 'name', 'city', 'state', 'country', ); // if the visitor supplied a search string, construct a where clause to search all the fields we want to search $search_string = @$_REQUEST['q']; if ($search_string) { $searchClauses = array(); foreach ($fieldsToSearch as $field) { array_push($searchClauses, "$field LIKE '%" . mysql_escape($search_string) . "%'"); } $where = join(' OR ', $searchClauses); } // if the visitor did not supply a search string, return all records else { $where = '1'; } list($records,) = getRecords(array( 'tableName' => 'listings', 'where' => $where, ));

I guess what I would like to see with this post is the following, assuming something like the search form page is named "search.php" and the viewer list page is named "searchListing.php":

1. what code goes on the top of each page
2. what code goes in the body of each page.
So, the above code...I have no clue as to which page it would go into, other than the top of one of them.

Re: [equinox69] Multiple Search Form

By Jason - October 12, 2010

Hi,

That code performs the search, so it would go at the top of the file that is going to display the search results.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Multiple Search Form

By Codee - October 12, 2010

So on the page with a search form (search.php) we would just use a standard CMSB search box like

<form method="POST" action="/path/to/your/searchListing.php">
<input type="text" name="name,city,state,country_keyword" value="">
<input type="submit" name="submit" value="Search">
</form>

???