Add search capabilities

EasyDoesIt is a tool for developing small web sites which, by definition, means you are going to have a small number of pages. Therefore you are not going to have the need to have a native search engine.

Despite of the previous, you can search using DuckDuckGo's web search just adding a form with some custom fields and a tiny Javascript, telling DuckDuckGo to search inside your site. We will make use of one of EasyDoesIt internal variables ($_host) to detect the host the results should be restricted to:

<div style="float: right; "> <form method="get" target="_search" action="https://duckduckgo.com/" onsubmit="do_search();"> <input id="q" name="q" type="text" value="" /> <input type="submit" value="Search" /> </form> </div> <script type='text/javascript'> function do_search() { document.getElementById('q').value = document.getElementById('q').value + ' site:<?php echo $_host; ?>'; return; } </script>

Please notice that the results are shown in a particular target window/tab ('_search') to avoid the proliferation of search windows and that the results make use of the HTTPS version of the search engine for increased user privacy.

The old way: Google

Previously we endorsed a method to use Google's search in your web site, but due to privacy concerns we now endorse the use of DuckDuckGo, Startpage or any other search engine. Anyway, if you are not sensitive regarding the privacy of your visitors, here is the old code:

<form method="get" target="_blank" action="http://www.google.com/search"> <input type="hidden" name="as_sitesearch" value="<?php echo $_host; ?>" /> <input type="hidden" name="ie" value="utf-8" /> <input type="hidden" name="ie" value="utf-8" /> <input type="hidden" name="oe" value="utf-8" /> <input type="text" name="q" id="q" value="" /> <input type="submit" value="Search" /> </form>

Or, if you need to restrict the search results to a path inside a domain, you can elaborate the code a little further adding a small piece of Javascript. You may need to customize the code replacing '/folder1/folder2/' for the value that match your installation:

<form method="get" target="_blank" action="http://www.google.com/search" onsubmit="document.getElementById('q').value=document.getElementById('q').value+' inurl:/folder1/folder2/';"> <input type="hidden" name="as_sitesearch" value="<?php echo $_host; ?>" /> <input type="hidden" name="ie" value="utf-8" /> <input type="hidden" name="ie" value="utf-8" /> <input type="hidden" name="oe" value="utf-8" /> <input type="text" name="q" id="q" value="" onclick="document.getElementById('q').value='';" /> <input type="submit" value="Search" /> </form>

Easy Does It

Creating small web sites, in an organized and easy fashion.

How to...

Lazy Badger Team

Lazy Badger

This is our war name regarding open software developing. We have a thing for badgers. You can be up to date about what we are doing by following us on Twitter.