Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

a big mess... (.cgi / frames question)

by Konda (Initiate)
on May 05, 2000 at 07:44 UTC ( [id://10315]=perlquestion: print w/replies, xml ) Need Help??

Konda has asked for the wisdom of the Perl Monks concerning the following question:

<HTML> I have a rather complicated problem involving perl, HTML, and .cgi in general. The answer may not necessarily involve perl, but perl might give a way around. I am grateful for anyone who takes time to look at this problem. It is for a senior project, and it involves displaying and altering a move list for a game of checkers.

I am using perl to activate a .cgi script that will update move list.

The activation (move entry, if you will) button is on a left half frame.

The updated move list (first , text, and then converted to a final, HTML format) is on the right frame, constantly refreshing.

This refresh occurs because the text file that the right hand frame needs to convert to HTML is not only changed by a user entering a move by clicking the "Done" button, but also by another user, altering that text file via FTP (no .cgi involved).

the example of the problem is at

http://www.rit.edu/~ee697b/cgi-bin/mast.html

enter 2 "coordinates" as shown on the right, and they will show up in the right hand frame

PROBLEM: The problem is, once the moves are refreshed, entering another move... I cannot figure out how to remove the extra frames that recursively pop in each time I enter a new move.

I have "locked" down the borders, but no matter what I do, the frames multiply. The screen real estate dwindles as the move list grows longer, and if the game goes on long enough, the list would disappear (a very unlikely situation, but is possible in an extreme case).

the source code for the necessary files involved is at:

http://www.rit.edu/~ee697b/cgi-bin/problem.txt

I would post the code here, but it's rather lengthy...

Can someone suggest a strategy for eliminating this problem? I have tried fooling around with many different "targets", frame names, writing permanent html files, or creating them with the script itself. Is there a way that perl can control any of what the frame does, or is it strictly an HTML problem? Are there any examples of other web pages out there that do this type of thing?

Thanks for your time. </HTML>

Replies are listed 'Best First'.
Re: a big mess... (.cgi / frames question)
by Maqs (Deacon) on May 05, 2000 at 20:03 UTC
    I took a glance at your source code and as far as I uncderstand your error is
    that you recurcuveky put FRAMESETS in yous old_ret subroutine. Try to make
    a stable HTML structure first and then fill it with your cgi output targeting
    neccessary frame.
    --
    With best regards
    Maqs.
Re: Big mess (.cgi/ HTML frames question)
by perlmonkey (Hermit) on May 05, 2000 at 00:54 UTC
    I think your problem might be with what HTML you are returning to the browser. But I am not very sure, since you logic was unclear to me. I had to rewrite some of this for my own sanity, so I hope you forgive me. This script will produce the frameset and each frame. All you need is this script and the coord.dat in the same directory. It uses the 'PATH_INFO' varaible for figuring out which page to print.
    #!/acclib/perl5/bin/perl my $path = $ENV{'PATH_INFO'}; my $file = 'coord.dat'; # Name the file print "Content-type: text/html\n\n"; #if no path print the frameset if( $path !~ /\S/ ) { print_frameset(); } #if script called with "/entry" appended then print the #left frame and parse the posted data elsif( $path =~ /entry/ ) { parse_form(); print_entry(); } #if script called with "/coord" appended then print the #right frame elsif( $path =~ /coord/ ) { print_coord(); } exit; sub parse_form { $buffer = 0; read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); # needed to convert from HTML receive 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; } #print data to file only if both fields were populated if( $FORM{'source'} =~ /\S/ && $FORM{'dest'} =~ /\S/ ) { open(FILE, ">>$file" ) || die; # Open the file for writing ( +append) print FILE "$FORM{source} - $FORM{dest}\n"; close FILE; } } sub print_frameset { print "<html>\n <head>\n"; print "<title>Match Results Thus Far</title>\n</head>\n"; print "<FRAMESET COLS=\"500,*\">\n"; print "<FRAME SRC=\"$ENV{'SCRIPT_NAME'}/entry\" NAME=\"left\" NORE +SIZE>\n"; print "<FRAME SRC=\"$ENV{'SCRIPT_NAME'}/coord\" NAME=\"right\" NOR +ESIZE>\n"; print "</FRAMESET>\n"; print "<body>\n"; print "<hr size=5 width=90%>\n"; print "<ul>\n"; print "\n$buffer\n"; print "<p>Script written by Neil Gaffin\n"; print "</body> </html>\n"; } sub print_coord { print "<html>\n <head>\n"; print "<title>Match Results Thus Far</title>\n"; print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5\" URL=\"$ENV{'SCRIPT_NAME'}/coord\" TARGET=\"right\">\n</head>\n"; print "<body>\n<h5>\n"; $lc = 0; open FILE, "$file"; my @lines = <FILE>; close FILE; while (@lines) { $lc += 1; print "<center> $lc -- $lines[0] </center>\n"; shift (@lines); } print "</h5>\n"; print "</body> </html>\n"; } sub print_entry { print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n"; print "<html>\n <head>\n"; print "<title>Neil's Script - Search Engine</title>\n</head>\n"; print "<body bgcolor=#FFFFFF text=#000000> <center>\n"; print "<h2>Move Database Page - File I/O</h2>\n </center>\n"; print "Use the form below to enter moves<br> \n"; print "Enter moves in format:<p>\n"; print "Source Space: Row,Col<br>\n"; print "Dest Space: Row,Col<p>\n"; print "Example: A8, H1, C5, G3<br>\n"; print "(Row must be A-H, Col must be 1-8<p>\n"; print "<hr size=7 width=90%><p>\n"; print "<FORM Action=\"$ENV{'SCRIPT_NAME'}/entry\" METHOD=\"POST\" target = \"left\" >\n"; print "<center><table border>\n <tr>"; print "<td>Source Space: </td><td> <input type=text name=\"source\" size=4><br></td>\n </tr><t +r>\n"; print "<td>Destination Space: </td><td> <input type=text name=\"dest\" size=4><br></td>\n </tr><tr>\ +n"; print "<th colspan=2><input type=submit value=\"Done!\"> <input type=reset><br></th>\n"; print "</tr></table></center></form>\n"; print "<hr size=7 width=90%><p>\n </body></html>\n"; }
    This code does not stack up the frames like yours does. Just save it as your fram.cgi and call it from you web browser. It worked for me. The path_info routing I found extremely useful when generating frames form a perl script, and I found it in the CGI.pm manual. You should probably upgrade this to use CGI.pm, it is much easier.

    Well I hope I have helped somewhat.
Re: a big mess... (.cgi / frames question)
by Anonymous Monk on May 05, 2000 at 19:23 UTC
    What are you refreshing the frame to? It may be as simple as telling the script not to send a document with <frame> in it, but the actual <frameset>. (If you are getting multiple frames in a frame, you are getting that frame as having more frames when it's reloaded.) Check that you are not reloading the entire (initial) frame html into that particular frame. Joe
Re: a big mess... (.cgi / frames question)
by perlmonkey (Hermit) on May 06, 2000 at 00:14 UTC
    I think Maqs is right about the recursive frameset.
    I replied to the other message you posted on the same topic: so look here

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://10315]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found