
Dave Phipps
Deleted
Jan 6, 2000, 12:03 PM
Post #1 of 4
(5455 views)
|
Passing 2 parameters/arguments to a script?
|
Can't Post
|
|
I want to call a script from a form within another script (actually the script is calling itself again, but you get the idea). Here is the start of the form: print $query->startform(action=>"$script_name/results?filename=$Answerfile", -TARGET=>"results"); One of the things that gets passed is the results of the form. The other is information after the ? in the path above(?filename=$Answerfile). It gets taken care of by the following code at the beginning of the script: my $Answerfile = param('filename'); #This is how the Answerfile path is passed Do you know how I can pass both of these things (the path and the results) to this script? They seem to conflict with each other. FYI, the reason this script calls itself is because it implements frames (it is a online quiz). One subroutine does the frame HTML, another makes the question/form window, and the last one makes results frame. Also, as you may have guessed by now, I'm using CGI.pm. For those of you who want to see my entire script, here it is (keep in mind, I'm new at this): Thanks in advance for any help you guys can provide. Dave #!/usr/bin/perl -w #use strict; use CGI qw(:standard); my $query = new CGI; my $Answerfile = param('filename'); #This is how the Answerfile path is passed my $script_name = "path for script"; my (@lines, @correct, @FromUser); my $line; my $i; my %hash = (); my ($question, $answer, $other_answers, $notes); my (@alt_answers, @temparray, @notesarray); my $oa; print $query->header; my $TITLE="Dave's Sample"; # We use the path information to distinguish between calls # to the script to: # (1) create the frameset # (2) create the question form # (3) create the query results my $path_info = $query->path_info; #my $path_info = param('path_info'); # If no path information is provided, then we create # a side-by-side frame set if (!$path_info) { &print_frameset; exit 0; } # If we get here, then we either create the question form # or we create the results. &print_html_header; &print_query if $path_info=~/questions/; &print_response if $path_info=~/results/; &print_end; # Create the frameset sub print_frameset { print <<EOF; <html><head><title>$TITLE</title></head> <frameset cols="70,30"> <frame src="$script_name/questions?filename=$Answerfile" name="questions"> <frame src="$script_name/results?filename=$Answerfile" name="results"> </frameset> EOF ; exit 0; } #This subprogram prints out the question side of the page sub print_query { print "<H1>$TITLE</H1>\n"; open(INFO, "<$Answerfile" ) or die "Unable to open $Answerfile $!\n"; @lines = <INFO>; close (INFO) or die "Unable to close $Answerfile $!\n"; $NumOfQuestions=@lines; print $query->startform(-action=>"$script_name/results?filename=$Answerfile", -TARGET=>"results"); for ($i=0;$i<$NumOfQuestions;$i++) { @alt_answers = (); @temparray = (); $_=$lines[$i]; chomp; ($question, $answer, $other_answers, $notes) = split(/\|/); #$hash{$question} = $answer; $correct[$i] = $_; @alt_answers = split(/\%\%/, $other_answers); $alt_answers[3] = $answer; push(@temparray, splice(@alt_answers, rand(@alt_answers), 1)) while @alt_answers; @alt_answers = @temparray; print "<P>$question<BR>", $query->radio_group( -name=> $i, -Values=>[$alt_answers[3], $alt_answers[0], $alt_answers[1], $alt_answers[2]], -linebreak=>'yes', -default=>' '); } print "<P>",$query->submit('Action','Submit'); print $query->reset; print $query->endform; } #This subprogram prints out the results in the frame on the right sub print_response { print "<H1>Results</H1>\n"; open(INFO, "<$Answerfile" ) or die "Unable to open $Answerfile $!\n"; @lines = <INFO>; close (INFO) or die "Unable to close $Answerfile $!\n"; $NumOfQuestions=@lines; $i=0; if(param(0) eq '') { print "Please submit your answers."; } else { for ($i=0;$i<$NumOfQuestions;$i++) { @alt_answers = (); @notesarray = (); @temparray = (); my $count = 0; $_=$lines[$i]; chomp; ($question, $answer, $other_answers, $notes) = split(/\|/); #$hash{$question} = $answer; $correct[$i] = $answer; @alt_answers = split(/\%\%/, $other_answers); @notesarray = split(/\&\&/, $notes); $alt_answers[3] = $answer; if (param($i) eq $correct[$i]) { print "<p>", $i+1, ") Your answer, ", param($i), " was correct!</p>\n"; } else { print "<p>", $i+1, ") Your answer, ", param($i), " was wrong! - the correct answer was ", $correct[$i], "<br>"; $x = 0; foreach $alt_answers (@alt_answers) { if(param($i) eq $alt_answers) { print "<br> Notes: "; print $notesarray[$count], "</p>"; } $count++; } #end foreach } #end else } #end for loop } #end else } #end print_response sub print_html_header { print $query->start_html($TITLE); } sub print_end { print $query->end_html; }
|