Gossamer Forum
Home : General : Perl Programming :

dual search options: checkbox or other method?

(Page 1 of 2)
> >
Quote Reply
dual search options: checkbox or other method?
webmasters:
I need guidance on how to allow users to choose whether to conduct searches with either SearchScript1 or SearchScript2. I'd like to offer the option from the same form to conserve layout space. Thank you in advance!
Quote Reply
Re: dual search options: checkbox or other method? In reply to
YES! This is exactly what I am looking for as well. If you find the answer, please email me at eliot@anthrotech.com.

Thanks.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: dual search options: checkbox or other method? In reply to
are you talking about one search script between 2 databases?

jerry
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Here's some clarity on what I'm seeking for the dual search options (from the same form, but using checkboxes, if possible).

SearchScript1: Search Links
SearchScript2: Search WWW


Thanks.
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Jerry,

Ideally something like what you are working on in the LINKS Modification Forum. I would like to allow my web visitors to search "the Net" and also my LINKS directory (and also with my site index file would be nice as well).

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: dual search options: checkbox or other method? In reply to
noguru,

I would check out the altavista.cgi Thread in the LINKS Modification Forum.

BTW: To do this type of search, you would need to have Sockets or LWP installed on your web server.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited October 24, 1999).]
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Eliot et al.,

I will restate my need in brief. I want users to be able to specify a search of EITHER (1) my site OR (2) the web from the same form. I do not need a script that searches the web. I just need something that lets users choose what they want to search.

If such a possibility does not exist, should I just create two separate forms?

Thanks to all in advance!
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Why not just the text box, and two radio buttons under it? Then depending on which radio button is chosen, the proper cgi script will execute.

--mark
Quote Reply
Re: dual search options: checkbox or other method? In reply to
mark,

could you provide a simple example of what you mean. maybe you can just provide the syntax for the radio buttons.

cheers,
noguru
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Something like this:

Code:
#!/usr/bin/perl -w

use CGI;

my $q = new CGI;

if ($q->param('search') eq "Local") {
&local_routine;
} elsif ($q->param('search') eq "Web") {
&web_routine;
} else {
&form;
}

sub form {
print $q->header,
$q->start_html('Perform A Search'),
$q->start_form,
$q->p($q->strong('Search For:')),
$q->textfield(-name => 'info'),
$q->submit(-name=>'submit', -value=>'Search Now!'),
$q->br,
$q->radio_group({-name => 'search', -values => [Local,Web]}),
$q->end_form,
$q->end_html;
}

sub local_routine {
my $info = $q->param('info');
print $q->header,
$q->start_html('Local Search'),
$q->p("This would be where the code to search locally for $info goes"),
$q->end_html;
}

sub web_routine {
my $info = $q->param('info');
print $q->header,
$q->start_html('Web Search'),
$q->p("This would be where the code to search the web for $info goes"),
$q->end_html;
}

--mark
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Mark:

Thanks for the script; however, how do I link this up with the radio buttons on the html page?

noguru
Quote Reply
Re: dual search options: checkbox or other method? In reply to
The code that Mark posted is self-sufficient. It uses the CGI.pm commands set. However, if you are not familiar with this, maybe this will look a little more familiar for you.

include in your html:
<input type="radio" name="search_type" value="local"> Local Search<br>
<input type="radio" name="search_type" value="www"> WWW Search<br>
----------------------
then you will have a conditional cgi that goes something like this:

#!/usr/bin/perl
use CGI qw(:standard);

# declare your var passed from the form
my $search_type = param("search_type");

# direct the process to the respective type
($search_type eq "local") ? &do_local : &do_www;

sub do_local {
# your local search code will go here
...
}
sub do_www {
# your www search code will go here.
...
}
--------------
Make sense? Try checking out perldoc CGI

-- Gordon --

------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Use these codes for the radio buttons:

Code:
<input type="radio" name="search" value="Local">Search our Site
<input type="radio" name="search" value="Web">Search the Web

If you would've read the codes that Mark gave, you would've seen that the field for the search mode is search with the values of Local and Web.

Keep in mind that the codes Mark provided needs CGI.pm installed on your server.

Wink

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Gordon,

I'd prefer to go with your script. However, I've tried without success to implement it.

I tried to follow your lead-ins, but I probably messed that up too. Please help me understand what's to be done, if you don't mind. I've inserted my questions to help you help me. Hope it helps?!?

-- beginning of your script --

# declare your var passed from the form
my $search_type = param("search_type");

<-Do I include the word used as my search variable, e.g., query? (What if the words differ for each SearchScript1 and SearchScript2?) ->


# direct the process to the respective type
($search_type eq "local") ? &do_local : &do_www;

<- Will this allow users to do either a local or www search? ->

sub do_local {
# your local search code will go here
...
}

<-Would this resemble http://www.dummydomain.com/cgi-bin/searchscript1.cgi (Is any punctuation required for detail or termination?)->

sub do_www {
# your www search code will go here.
...
}

<-Would this resemble http://www.dummydomain.com/cgi-bin/searchscript2.cgi (Is any punctuation required for detail or termination?)->

-- end of your script --

Thank you so much for your assistance. Your effort is sincerely appreciated.
Quote Reply
Re: dual search options: checkbox or other method? In reply to
I'm using "query" as my form variable from the text box. For the local and www searches I've typed:

http://www.dummydomain.com/cgi-bin/searchscript1.cgi?search_param=\$search_type;

BUT when I check it in perl, I get responses like "Search line not terminated." and a bunch of other stuff. Uugh! Charlie Brown!

What am i doing wrong?!?
Quote Reply
Re: dual search options: checkbox or other method? In reply to
<-Do I include the word used as my search variable, e.g., query?
What if the words differ for each SearchScript1 and SearchScript2?) ->
Yes, you would put your variable name there.
my $search_type = param("your_form_variable");


<- Will this allow users to do either a local or www search? ->
It will allow the script to go to the correct subroutine according to what choice they make with the radio buttons.


As to the last two, yes you would put your code for your local search in the first sub and the code for the www search in the second sub. if you just wanted to direct it to another cgi from there you would have to pass all the vars with it, which would be a pain in the arse. perhaps have the first sub have all of your local search code and have the second sub just have a link. like:
sub do_www {
print "Location: http://www.dummydomain2.com/search.cgi?search_param=$search_type\n\n";
}

good luck Smile
-- Gordon --

------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Hrm,
i suggest readin some online docs about CGI's and Perl programming.
Check out http://www.devshed.com
and http://www.perl.com and while you're at it, try reading through
http://www.perl.com/...gi/perl-cgi-faq.html

If that doesn't do it, look into contracting Smile
-- Gordon --

------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Just use LWP and fetch the search result page according to the user input, format it and display. This way you don't have to modify the search scripts.
Baris.

------------------
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Need: Multi-Search Form Redirect

I'm thinking too hard and racking my brain without success.
Please help me figure out my simple mistake(s). Ugh!

Basically, I want the following:

- redirected form submission per 1 of 3 drop-down options
- auto-submit (likely javascript) of pre-filled form entry
- note: keyword cannot be passed via URL string

#!/usr/bin/perl
use CGI;
my $q = new CGI;
if ($q->param('search_type') eq "search1") {
&search1_routine;
} elsif ($q->param('search_type') eq "search2") {
&search2_routine;
} elsif ($q->param('search_type') eq "search3") {
&search3_routine;
} else {
&form;
}
sub form {
print $q->header,
$q->start_html('Perform A Search'),
$q->start_form,
$q->p($q->strong('Search For:')),
$q->textfield(-name => 'keyword', -value=>'findx'),
$q->submit(-name=>'Search', -value=>'Search'),
$q->br,
$q->radio_group({-name => 'search_type', -value => [search1,search2,search3]}),
$q->end_form,
$q->end_html;
}

sub search1_routine {
my $keyword = $q->param('keyword');
print $q->header,
$q->start_html('Site Name - keyword'),
$q->p(print "<form method=post action=http:www.myurl.com/cgi-bin/search/search1.cgi>\n"),
$q->p(print "<input type=text name=keyword value=$keyword>\n"),
$q->p(print "</form>\n\n"),
$q->end_html;
}
"ditto (search2 and search3)"


Thanks in advance.

Quote Reply
Re: dual search options: checkbox or other method? In reply to
Why can't you pass it along a query string?

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Show us a code example of what you mean Andy. Maybe a little script to show how this would be done.

Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/

Quote Reply
Re: dual search options: checkbox or other method? In reply to
Paul, what I was asking was a question to 'noguru' to see why he couldn't pass the query via a string;

In Reply To:
- note: keyword cannot be passed via URL string
Just to clear things up a bit Wink

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Yes I know, and I was saying why not give an example of how this could be done.

Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/

Quote Reply
Re: dual search options: checkbox or other method? In reply to
Something like;

#!/usr/bin/perl
use CGI;
my $query = new CGI;
$queryword = $query->param('query');
$action = $query->param('action');

if ($action eq "searchengine1") { &gotosearch1; } elsif ($action eq "searchengine2") { &gotosearch2; } else { &error; }

sub error
{
print header;
print "Sorry, there was an error with the query you submitted. Please try again \n";
}

sub gotosearchengine1
{

print "Location: http://www.someplaceforanotherengine.com/cgi-bin/anothersearchscript.cgi?query=$queryword \n\n";

}

sub gotosearchengine2
{

print "Location: http://www.someplace.com/cgi-bin/searchscript.cgi?query=$queryword \n\n";
}

This is a very basic idea, as you could add error checking etc. but obviously it reuiers them to be able to use a query string, so for this case it isn't much help Wink

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: dual search options: checkbox or other method? In reply to
Check that code again and spot the major mistake.

Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/

> >