Gossamer Forum
Home : Products : DBMan : Installation :

Searching DBMan On an HTML Page

Quote Reply
Searching DBMan On an HTML Page
Hi,

Is it possible (with a default user set, of course) to place a small search form to search DBMan on any normal HTML page? I was thinking about that so you could also tell people "Add a search form for this database to your site!"...

Man, this is like 4-5 mod ideas in one night...if I could only learn Perl I'd always have something to do. Smile

Chris
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Picked this out of my notes Smile


Here is a simple chunk of code that makes a form work from outside dbman, you could easily make it work from within dbman.

code:

<form method="get" action="http://www.yourdomain.com/cgi-bin/dbman/db.cgi">
<input type="hidden" name="db" value="default">
<input type="hidden" name="uid" value="default">
<input type="text" name="TITLE" size="15">
<select name = "index"><option value= "---" selected>Select One<option value= "books"> Books<option value= "music"> Chairs </select>
<input type="submit" name="view_records" value="Search"></form>

It is fun to think of all the possibilities using DBMan isn't it Smile

And what's really great is almost anything you can think of has already been created and can be found in old threads. And by searching through many of the old threads you find out things you never would have thought of yourself Smile

I'm hoping to very soon be able to send JPDeni another list of mods she has written, and their location, so they can be made available again.

JPDeni has been very busy on these forums for quite awhile helping hundreds of people create various applications and to learn how to utilize this script. What a wonderful person .. eh?
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Lois,

I don't quite follow...that looks like a dropdown menu there...I was just looking for a small form which basically has one field...is it possible to have one search field search for the keyword(s) entered in ALL the fields in the database?

Chris
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Yep.

Code:
<form method="get" action="http://www.yourdomain.com/cgi-bin/dbman/db.cgi">
<input type="hidden" name="db" value="default">
<input type="hidden" name="uid" value="default">
<input type="hidden" name="view_records" value="1">
<input type="text" name="keyword" size="15">
<INPUT TYPE="SUBMIT" NAME="view_records" VALUE="Search">

Users can type in the search term and then either click the "Search" button or hit the enter key.


------------------
JPD






Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Carol,

Wow! That's amazing...is the form path the only thing I need to change?

Chris
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Yep. That's it. The rest is "cut-and-paste" into your .html file.


------------------
JPD






Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Is there also a way to only search 2 fields in one search box? In this case it would be the fields "Title of Article" and "Article"

Chris Smile
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Chris:

You'll notice in the first example I included a few different ways to use this. See where I have the title field included? You just change that field to match the field name in your database Smile

I also put in the option fields just in case you wanted to do that also. Just use the example above and you should easily be able to see how to include whichever fields you want in your search form.

Hope this helps Smile
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Lois,

Actually I'm rather dumb when it comes to this, I tried messing around with it but couldn't get anything to work! Frown

The perfect form for me would be a text box where you type in a search term, and then a dropdown box where you choose what field to search by, either "Title of Article", "Article", "Author"...I've tried to figure out how to do this but can't figure it out Frown

If this is a pain a simple 1 field form that searches through 2 fields at once would do a very suitable job of what I'm trying for! Smile

Chris
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
Oh. This is a tricky one. Let me read this again. One sec.

Okay. I think this can be done. (Thinking cap now firmly planted.)

Use the form that I posted earlier, but instead of the "keyword" field, use the name search_term. Then create a select box with the name search_field that has exactly the names of the fields that people can search on. You can even have an "All fields" option if you want. The select field would look like this:

Code:
<SELECT name="search_field">
<OPTION value="keyword">ALL</OPTION>
<OPTION>Title of Article</OPTION>
<OPTION>Article</OPTION>
<OPTION>Author</OPTION>
</SELECT>

You can add as many as you want, but they must match exactly the names of the fields as defined in your .cfg file.

Then, go to db.cgi, sub query. After

local (%sortby);

add

Code:
if ($in{'search_term'}) {
$in{$in{'search_field'}} = $in{'search_term'};
}

I think this might work! This was a new one for me, though. Smile


------------------
JPD






Quote Reply
Re: Searching DBMan On an HTML Page In reply to
P.S. Don't forget to define the option values Smile

I believe you would need to include the field values for EACH option Smile Change the value=" " to match your database field names.

<SELECT name="search_field">
<OPTION value="keyword">ALL
<OPTION value="title">Title of Article
<OPTION value="article name">Article
<OPTION value="author">Author
</SELECT>

Hope this helps Smile
Quote Reply
Re: Searching DBMan On an HTML Page In reply to
I don't think it's absolutely necessary, although it may be good HMTL coding practice. I know that the regular select fields that DBMan generates do not have "value" tags in them and things work just fine.

From my understanding, if there's no "value" for the option, the displayed text is sent to the script from the form. If there is a "value," the value is sent.

I just looked again at the subroutine that builds the select fields and it appears that it's not even necessary to include the closing </OPTION> tags. Again, it may be better HTML coding practice, but it seems to work without it.

Chris, if you do include "value" tags for each option, be *absolutely certain* that the "value" tag exactly matches the name of the field as defined in your .cfg file. Whatever goes to the script must match the name of a field. Otherwise you'll get a "no search terms defined" error.


------------------
JPD






Quote Reply
Re: Searching DBMan On an HTML Page In reply to
For a long time I never bothered to use many of the closing tags in HTML, until I then discovered that Netscape insists on them. IE doesn't seem to mind - maybe it has more grey matter built in. Have you checked your html with Netscape? Most people (judging by logs on some of my sites) use IE4 or 5, but I understand that Netscape is widely used in Canada. No comments or reasons for this, please. I don't wish to upset my Canadian friends.
BTW, a couple of weeks ago I posted some problems I was having installing DBMan. It is now installed fine. Putting all the files in a subdirectory of cgi-bin seemd to cure the problem all on its own.
Now I trying to customise the html script to give some better looking forms.
I'll be back!

------------------
David Olley
david@afil.co.uk