osCommerce Knowledge Base
Add the Search Form To Other Pages | Last Update: 17th August, 2005 Article ID: 55 |
- Introduction
- Solution
- Using Only HTML Code
- Using HTML and PHP Code
Introduction
The product search form can be added to any page on the site using only HTML code, or to any page on the catalog using HTML and PHP code.
The preferred method is to use HTML and PHP code otherwise the customers session may be lost when cookies are disabled and the session ID does not exist in the URL.
Solution
- Using Only HTML Code
- Using HTML and PHP Code
Using Only HTML Code
Using only HTML code allows the product search form to be added on any page on the site (outside the osCommerce insallation) but has the disadvantage of not retaining the session ID in the URL if cookies have been disabled.
<form name="quick_find" method="get" action="http://www.example.com/advanced_search_result.php">
<input type="text" name="keywords" size="10" maxlength="30" value="" style="width: 115px">
<input type="submit" value="go">
<a href="http://www.example.com/advanced_search.php">Advanced Search</a></form>
If you have put your search form in your header you can have it search in the descriptions along with the title.
Add this code to search in descriptions:
<input type="hidden" name="search_in_description" value="1">
The final code would look like this:
<form name="quick_find" method="get" action="http://www.example.com/advanced_search_result.php">
<input type="text" name="keywords" size="10" maxlength="30" value="" style="width: 115px">
<input type="hidden" name="search_in_description" value="1">
<input type="submit" value="go">
<a href="http://www.example.com/advanced_search.php">Advanced Search</a>
</form>
Using HTML and PHP Code
Using HTML and PHP code allows the session ID to be retained, but can only be used on pages inside the osCommerce installation. Be careful not to place this code inside of an existing form submission however!
<?php echo tep_draw_form('quick_find', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get') . osc_draw_input_field('keywords', '', 'size="10" maxlength="30" style="width: ' . (BOX_WIDTH-30) . 'px"') . ' ' . tep_hide_session_id() . osc_draw_hidden_field('search_in_description' , '1') . tep_image_submit('button_quick_find.gif', BOX_HEADING_SEARCH) . '<br>' . BOX_SEARCH_TEXT . '<br><a href="' . tep_href_link(FILENAME_ADVANCED_SEARCH) . '"><b>' . BOX_SEARCH_ADVANCED_SEARCH . '</b></a></form>';?>
