Return CGI Library
This gadget does a simple string search through a tab delimited text file, and returns all the matches in a table.
Two or three files drive this gadget: an input form or link, a data file, and an optional format file.
The format file is the simplest part. If it exists, it is the HTML page which the table is dropped into. The gadget scans this
file looking for the tag <!FIND> and drops the table in the file at that point. If the file does not exist then the output page
is simply the table and it's contents...
Here's what is in the sample format file:
<img src="http://baremetal.com/images/bm.jpg" alt="Baremetal.com" />
That's all folks!
<a href="http://baremetal.com/gadgets/find/">Go Back</a>
The datafile is the next simplest component.
The first line is the field NAMES separated by tabs. The rest of the lines are the data... each field separated by a tab, and the
lines/records separated by an newline character. (A newline is a line feed, and the carriage return of the CR-LF from dos won't cause
any harm in html.)
The example datafile is shown between the <hr />'s:
Name: Web Site:
tbrown website is: <a href="http://baremetal.com/">baremetal.com</a>
sun over here: <a href="http://www.sun.com/">www.sun.com</a>
ibm over here: <a href="http://www.ibm.com/">www.ibm.com</a>
vvv.com over here: <a href="http://www.vvv.com>www.vvv.com/"</a>
Now an explanation of filenames. The data-file and the template-file must be in the same directory. They must have the same root file
name with ".data" and ".tplt" suffixes respectively. In the upcoming example we will use searchname as the root of the file name, so
the files become searchname.data and searchname.tplt respectively.
Sample Input Form:
Here is an example form... HTML showing first, and then the actual working form below:
<form action="/cgi-bin/find.pl/gadgets/find/ex.find" method="post">
search text: <input type="text" name="f_find" />
<input type="submit" value="search" /> <br />
border <input type="text" name="f_border" value="0" /> <br />
padding <input type="text" name="f_padding" value="5" /> <br />
halign <input type="text" name="f_halign" value="left" /> <br />
dalign <input type="text" name="f_dalign" value="left" /> <br />
Building the form:
Setting up the form is the tricky part. There are a number of important parts to the form. The <form action=...> line is probably
the most important. The action= parameter contains /cgi-bin/find.pl and the root filename as it would appear to the webserver. If
/gadgets/find/ex.find.data was the URL that would load the datafile, then the "action=" clause will be:
(Note there seems to be bug in the web server software that sometimes drops a .html suffix on the file name ... be carefull about
that... the script will tell you when it can't find or read the datafile... that's why the example used here is ex.find instead of
A few moments to explain the extra fields after the SEARCH button :-)...
The border, padding, halign, and dalign parameters affect the display of the table. The default values are shown in the table above...
There is a quick search version of this...
Will bring up the records matching "tbrown" ... note that if you understand the GET syntax of CGI you can pass the other fields in as
(e.g.: Find tbrown ).
Ask at firstname.lastname@example.org if you need help...
A maximum hit count HAS been implemented. It defaults to 100. Ask email@example.com
for instructions on how to change it. [It isn't posted here to stop people from writing their own forms and stealing your whole
We setup the gadget so that it dumps the whole database (well, up to the maximum hit count # of lines) if there is no search string.
For smallish tables this is nice (e.g. the example)
The gadget is by default NOT case-sensitive.
To turn on case sensitivity, add:
<input type="hidden" name="f_case" value="Y" />
to your form.