Forum Moderators: coopster & phranque

Message Too Old, No Replies

cgi site search results needs to load into different frame

         

doharr

6:40 am on Feb 8, 2008 (gmt 0)

10+ Year Member



This is a tested and working web site search script. My problem with it, I need to have the results redirected into a different window, ie: main.html. It loads back into the same window now. .

[snip]

I tried some reconfiguring of this line under Print the matched record, with out success.

print "<LI><A HREF=". $linkurl . ">" . $linktitle . "</A> : $linkdescrip</B><BR>\n";

Thank you in advance for any help

This is the Script Below.

#!/usr/local/bin/perl
####################################################################
# URL Search Engine
# Copyright 1996 [snip]
# Written By : [snip]
# Date Last Modified : Jan 14, 1997
####################################################################
#
# This script is free of charge.
# Please link back to [snip], thank you :-)
#######
#
# Jan 14, stops people from entering html tags, converts < to &lt;
#
####################################################################

# $linktitle, $linkdescrip, $linkwords, $linkemail, $linkurl
# define some global variables

$fields = 5; # Number of fields in each record
$filename = "urls.txt"; # The database text file
$results = 1000; # maximum number of results to display

&parse_form;

$searchstring = $FORM{'searchstring'};

&addrecord if ($searchstring eq "**ADD RECORD**");

&open_file("FILE1","",$filename);

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<BODY BGCOLOR=#FFFFFF TEXT=#000000 LINK=#0000FF VLINK=#800040 ALINK=#800040>\n";
print "<TITLE>Search Results</TITLE>\n";
print "<CENTER><BR>\n";
print "<FONT SIZE=5 COLOR=000000 FACE=\"ARIAL,TIMES NEW ROMAN\">Search Results</FONT></CENTER>\n";

print "<HR width=80% noshade><BR><UL>\n";
$counter = 0;

while (($line = &read_file("FILE1")) && ($counter < $results)) {
# split the fields at the ¦ character
@tabledata = split(/\s*\¦\s*/,$line ,$fields);
&check_record;
if ($found == 1) {
$counter++;
&print_record;
}

}
close(FILE1);
print "</UL>\n";

if ($counter == 0) {
print "<BR><B> Sorry, No Matches were found.</B>\n";
}


print "<CENTER>\n";
print "<HR width=80% noshade>\n";
print "<FONT SIZE=3 COLOR=000000 FACE=\"ARIAL,TIMES NEW ROMAN\">URL Search Brought to you by : <A HREF=\"http://www.example.com\">Anytown Bunk and Trash Your OEM Parts Source</A></FONT></CENTER>\n";
print "</CENTER>\n";
print "</A></BODY></HTML>\n";

#########################################
#
# Print the matched record
#
#########################################
sub print_record {
print "<BR>\n";
print "<LI><A HREF=". $linkurl . ">" . $linktitle . "</A> : $linkdescrip</B><BR>\n";
}

##########################################
#
# Check to see if record matches search criteria
#
##########################################
sub check_record {
# get the data from the record read from the file. $tabledata

$linktitle = $tabledata[0];
$linkdescrip = $tabledata;
$linkwords = $tabledata[2];
$linemail = $tabledata[3];
$linkurl = $tabledata[4];
chop($linkurl);

#build the search line with all fields we want to search in
$searchline = $linktitle . " " . $linkdescrip . " " . $linkwords;

#search by keywords
# only perform the keyword search if the length of the search string is greater than 2
# don't think we want people to search for and or or etc.
$sfound = 0;
$found = 0;
$notfound = 1;

$stlen = length($searchstring);
if ($stlen > 1) {
@words = split(/ +/,$searchstring);
foreach $aword (@words) {
if ($searchline =~ /\b$aword/i) {
$sfound = 1;
}
else {
$notfound = 0;
}
}
}
if ($sfound == 1 && $notfound == 1) {
$found = 1;
}

# if search string is too small .. set found to 1
if ($stlen <= 1) {
$found = 1;
}
#if page doesn't have a title then return not found
$tlen = length($linktitle);
if ($tlen < 1) {
$found = 0;
}
}

############################################
#
# Add Record
#
############################################

sub addrecord {

$linktitle = $FORM{'linktitle'};
$linkdescrip = $FORM{'linkdescrip'};
$linkwords = $FORM{'linkwords'};
$linkemail = $FORM{'linkemail'};
$linkurl = $FORM{'linkurl'};

# Convert < tags to &lt;
$linktitle =~ s/</\&lt;/g;
$linkdescrip =~ s/</\&lt;/g;
$linkwords =~ s/</\&lt;/g;
$linkemail =~ s/</\&lt;/g;
$linkurl =~ s/</\&lt;/g;


&open_file("FILE1",">>",$filename);

&write_file("FILE1",$linktitle . "¦". $linkdescrip. "¦" .$linkwords ."¦" .$linkemail ."¦" .$linkurl ."\n");
close(FILE1);
print "Content-type: text/html\n\n";
print "<html><head><title>Thank You</title></head>\n";
print "<body><BR><h3><CENTER>Thank You For Adding to this database</CENTER></h3>\n";
print "</body></html>\n";
exit;
}

sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}

@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}
}

sub open_file {

local ($filevar, $filemode, $filename) = @_;

open ($filevar,$filemode . $filename) ¦¦
die ("Can't open $filename");
}

sub read_file {

local ($filevar) = @_;

<$filevar>;
}

sub write_file {

local ($filevar, $line) = @_;

print $filevar ($line);
}

[1][edited by: phranque at 8:29 am (utc) on Feb. 8, 2008]
[edit reason] removed specifics [/edit]

rocknbil

3:35 pm on Feb 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard doharr, wherever your form is,

<form method="post" action="yourscript.cgi" target="frameName">

Where frameName is the named frame in your frameset:


<frameset rows="100,*">
<frame name="nav" id="nav" src="nav.html">
<frame name="frameName" id="frameName" src="main.html">
</frameset>

doharr

7:16 pm on Feb 8, 2008 (gmt 0)

10+ Year Member



Rocknbil,

Thank you for your reply, it really helped. Your information did stop it from reloading into the same window. That was a big help. (I now understand I should have been looking in a different area for the solution.)

But it didn't do completely what I was looking for.

It now opens up in a different window. I thought, I called out for it to load into the main.html frame, but it now opens a new IE window and shows up there.

I would appreciate any additional help, from anyone!

Thanks,
doharr

perl_diver

8:02 pm on Feb 8, 2008 (gmt 0)

10+ Year Member



doharr,

are you using a frameset document or a regular html page? If a regular html page:

target = '_top';
target = '_blank';
target = '_new';

one of those should work.

rocknbil

4:08 pm on Feb 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It now opens up in a different window. I thought, I called out for it to load into the main.html frame, but it now opens a new IE window and shows up there.

Look at my original example again. When you target a link or a form, there has to be a named frame to target it to. If there isn't, it will do as you said - open a new window (and the "name" of that window will be whatever your target is.)

In my example I named the frame containing main.html "frameName". So you don't want

target="main.html"

because "main.html" is the content of the frame named "frameName." You want

target="frameName"

Also the originating form has to be part of the frameset. So your search form has to be one of the files in the current frameset. If you're hoping to target a frameset from a different page, that's a different story. What you need to do then is build the frameset on the fly.

doharr

5:42 pm on Feb 9, 2008 (gmt 0)

10+ Year Member



IT WORKS!
Thanks for all the great Help!
It was very appreciated.