Add Wikipedia search box to blog

There’s always a way to do this sort of thing and Wikipedia is a splendid example of exactly how to reverse engineer a search box and pour it into a rudimentary form. Let’s dig into it and you’ll see what I mean!!

Go to the site’s home page and you’ll see that they have a very simple search box with no fancy bells and whistles:


The only fancy part is the language selector, but that’s easily duplicated if you want to be truly polyglot on your site. If not, the default is English so that might work just perfect for your needs.

One way to do this is to just copy and paste from their page source, which looks like this:
[ad]

I prefer doing things for myself, however, but this gives me all the information necessary: the name of the target CGI search utility and the names of the variables involved. Stripping it to its most basic, pre-selecting English, and carrying across the hidden variable from the source, here’s how a crude Wikipedia search might look:

<form action=”http://www.wikipedia.org/search-redirect.php” method=”get”>
<input type=”text” name=”search” size=”20″ />
<input type=”hidden” name=”language” value=”en” />
<input type=”submit” name=”go” value=” > ” />
<input type=”hidden” name=”go” value=”Go” />
</form>

Turns out we can clean this up just a little bit and make it more friendly too:

<form action=”http://www.wikipedia.org/search-redirect.php” method=”get”>
Search Wikipedia:
<input type=”hidden” name=”language” value=”en” />
<input type=”text” name=”search” size=”20″ />
<input type=”submit” name=”go” value=” Go! ” />
</form>

That’s all there is to it. Here, try it:

Search Wikipedia:

Simple enough, eh? Hope that helps you tap into the splendid resource that is Wikipedia.
[ad#mo]