« See all FAQs for Accentuate Premium HTML Theme / Business Portfolio

How can I get the search form to work?

When it comes to search features for websites, there are a lot of options out there. Many require a bit of PHP work. In order to avoid extra programming I want to recommend a very simple solution; Google custom search. Here is a very simple example that you can copy.

Step 1: Do this on the page you want the search to work on. (You could try it on one page before doing a full find and replace all for the entire site.)

1. Find:

<!--SEARCH --> <div class="search"> <div class="search-box"> <form action="#"><!-- Search Feature --> <input name="search" type="text" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Search this site':this.value;" value="Search this site" /> <input name="submit" type="submit" id="search" value="" /> </form> </div> </div> <!-- /SEARCH -->

Step 2: Replace with

<!--SEARCH --> <div class="search"> <div class="search-box"> <form action="http://www.google.com/custom" method="get"> <!-- Search Feature --> <input name="q" type="text" value="Search this site" onfocus="this.select()" onclick="this.value='';" onblur="this.value=!this.value?'Search this site':this.value;" /> <input name="sitesearch" type="hidden" value="themeforest.net" /> <input name="submit" type="submit" id="search" value="" /> </form> </div> </div> <!-- /SEARCH -->

Step 3. Change value=”themeforest.net” to your website URL . I.e. value=”yourURLhere.com”. (without the prefix http://)

changes explained

1. The name of the search input changes:

Before: name="search"
After: name="q"

2. The form action and method are added to the form tag.

Before: <form action="#" />
After: <form action="http://www.google.com/custom" method="get" />

3. A new hidden input is added, this determines which site (URL) is searched. You must change value=”themeforest.net” to your value=”your website URL ”. Otherwise you can leave this line out and it will search the entire web. Your website must be index by Google before it will show in the results.

<input name="sitesearch" type="hidden" value="themeforest.net" />

This example will open the results on a new page at Google, if you want to make the results appear on your website, a little more setting up is needed. Google can explain is much better than I can, please visit http://www.google.com/cse/docs/cref.html for more info.