← Back to Archives

A Search Bar in Firefox for California Election Code

blogging

If you use FireFox, you can create search bars for almost any search form out there. I just created one for the California Election Code.

small screen shot of CA Election Code search bar

If you frequently find yourself searching the California Election Code, you might want to simply install this search bar plugin. I'll also give a quick tutorial for how to create your own if you search a body of code frequently (like the JAVA API for all you SIMS first-years).

[More:]

Please let me know if you find any of this confusing, unclear or incorrect.

Installing the California Election Code Search Bar in Firefox

  1. Download the following files:
    http://pobox.com/~joehall/ca_elec_law/ca_elec_law.src
    and
    http://pobox.com/~joehall/ca_elec_law/ca_elec_law.png
  2. Copy these files to the searchplugins/ folder in your FireFox installation directory. On my Mac, this is:
    /Applications/Firefox.app/Contents/MacOS/searchplugins/
  3. Quit and restart FireFox.
  4. Now, you can use the California Election Code search bar by selecting the search with the california seal icon, 16x16 CA seal thumb. Note: On the Mac, you can use the Command-K shortcut to jump to the search bar, and Ctrl-Up and Ctrl-Down to change search engines.

What About Other Search Forms?

Well, here's a way to adapt my plugin above to your frequently searched database of choice:

  1. Copy the SRC file from my example above and rename it to a short title for your new search bar.
  2. Open it in a text editor.
  3. Change the comments to reflect your details.
  4. Change the name of the plugin and the description to something appropriate for your new search bar.
  5. Open the search form for the search bar you want to create. Also, view the source in another window.
  6. Enter the URL of the search form as the searchform parameter.
  7. In the source code for the search form page, find the FORM tag near the beginning of the page. Note that the method must be "GET" for this to work (that is, if it isn't GET, the mycroft scheme that I'm describing here won't work. See UPDATE below.).
    Copy the action tag plus the root URL for the site to the action parameter in the SRC file. For example, for the California Legal Code query form, the FORM action is "/cgi-bin/calawquery". When I add this to the root URL for the form I get:
    action="http://leginfo.ca.gov/cgi-bin/calawquery"
  8. Do a typical query in the normal webpage-based search form that you'd like to be able to do from the search bar. Note other parameters that appear in the URL. Note which parameter is the query text (what you want to search for). The query text parameter goes in the <input> tag with user in it. The other parameters that appear in the URL for the executed query can be entered as additional unchanging <input> tags in the SRC file.
    For example, a simple query on the CA Election Code returns:
    http://leginfo.ca.gov/cgi-bin/calawquery?codesection=elec&codebody=test&hits=All
    Note that in my SRC file I added the two parameters codesection and hits with their typical values (note that lowercase/uppercase counts!).
  9. For a simple "Semi-plugin" like my example, leave the INTERPRET section alone... this is for sidebar-returned search results.
  10. Update where people can find your plugin in the BROWSER section of the SRC file.
  11. Validate the syntax of your plugin. There you can also test it out and check the rendering of the search URL. Note: if you don't have a mycroft URL entered in the BROWSER section of the SRC file, the validator might alert you of this... you can ignore this until after you've submitted your plugin to mycroft.
  12. Create a 16 pixel by 16 pixel PNG file for your search bar. Call it the same as the filename of your SRC file save the file extension.
  13. Copy the SRC and PNG files to the searchplugins directory of your FireFox installation. Quit and restart FireFox. Your plugin should now work.
  14. You can submit your plugin to the mycroft search plugin database.

UPDATE [2004-11-29 11:41]: Actually, if you see a POST form, you can try to use the following bookmarklet (create a dummy bookmark and then copy and past this text (all one line) into its URL field):

javascript:(function(){var x,i; x = document.forms; for (i = 0; i < x.length; ++i) x[i].method="get"; alert("Changed " + x.length + " forms to use the GET method. After submitting a form from this page, you should be able to bookmark the result."); })();

Use this while you're at the form's page to try and change the POST to a GET. If it works, you can forget the form source ever said POST and just use GET in your plugin. (this is via the mycroft site citing Jesse Ruderman's bookmarklet page.