Search Field Issue

11 posts by 3 authors in: Forums > CMS Builder
Last Post: July 14, 2011   (RSS)

How do I define my search box on my page to search the brand?

All my products are associated with a brand. I want the search results to go to my brandsList.php page and I want the keyword search to search the brand that they type in. This is my sample code which is not working.

<form method="POST" action="brandsList.php" class="searchForm">

<td height="49" valign="top"><input name="name_brand" type="text" value="" class="field" id="search" /></td>
<td height="49" valign="top"><input name="submit" type="image" value="SUBMIT FORM" src="images/button-go.jpg" border="0"></td>
</form>

Re: [dccreatives] Search Field Issue

By Jason - June 16, 2011

Hi,

You can do this by adding _keyword to an input field that has the same name as the field you want to search.

So, assuming your brand field in your section is called "name_brand" you can use a field like this:

<td height="49" valign="top"><input name="name_brand_keyword" type="text" value="" class="field" id="search" /></td>

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] Search Field Issue

I currently have a search field that searches the name of the product. I added in the section editor a field called search_words. Which are basically other names that this product can go by, and I want it to show the results if entered into the search field.

I have a product called Sushi Wall. Some resellers call it SUW. I added to the search_words field, SUW, sushi for this product. Now how do I add it to the current search code?

<input name="name_keyword" type="text" value="" class="field" id="search" />

I tried this: <input name="name_keyword, search_words_keyword" type="text" value="" class="field" id="search" /> but it did not work.

Any suggestions?

Re: [dccreatives] Search Field Issue

By Dave - July 12, 2011

Hi dccreatives,

Try replacing this:
<input name="name_keyword, search_words_keyword" type="text" value="" class="field" id="search" />

With this (spaces and first "_keyword" removed):
<input name="name,search_words_keyword" type="text" value="" class="field" id="search" />

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [dccreatives] Search Field Issue

By Jason - July 12, 2011

Hi,

Can you use the
'debugSql' => true,
option so that we can see what the actual query is?

Thanks
---------------------------------------------------
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: [dccreatives] Search Field Issue

By Dave - July 12, 2011

And/or post the url to your viewer page if you are able.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Search Field Issue

I think I know what the issue is. I added the code below to the search.php page to get rid of the white spaces



// remove white space
if (@$_REQUEST['name_keyword']) {
$_REQUEST['name_keyword'] = str_replace(" ", "", $_REQUEST['name_keyword']);
}

list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'where' => "REPLACE(name, ' ', '') LIKE '%".mysql_escape(@$_REQUEST['name_keyword'])."%'",
//'debugSql' => true,
'allowSearch' => false,
'limit' => '45',
));

I think I need to add the 'search_words' field as well to these statements in order for it to work not just the name_keyword.

How do I do this?

Re: [dccreatives] Search Field Issue

By Jason - July 13, 2011

Hi,

If search_words has the name in a number of different formats (including without spaces), then you can remove the code that remove white spaces, and turn on automatic searching like this:

list($itemsRecords, $itemsMetaData) = getRecords(array(
'tableName' => 'items',
'limit' => '45',
));


That should do the search for you.

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] Search Field Issue

Problem is that it will take me time until all the search_words get filled in and in the meantime, my search will not work properly. Is there any way to get it to work with both searching the name_keyword and the search_words?

Thanks