chriso has asked for the wisdom of the Perl Monks concerning the following question:
The first time I run makequiz.cgi and answer the questions and submit them, the scripts run just fine. If I then go back and click the link again to execute makequiz.cgi, the questions are displayed ok, but when I submit the questions to gradequiz.cgi,
1. not all of the variables are passed to gradequiz. It grades the quiz indicating which questions are wrong/right but it does not pass the correct and incorrect answers or the user's name 2. It lists all the questions twice, questions 1-5 which it grades accurately, then redisplays the questions as 6-10, all of which are marked as wrong.If I repeat the above by clicking the link to start the makequiz.cgi script, it does the same thing listed above only it now displays the questions 3 times, meaning it shows 15 questions. I'm sure it is something simple but I'm lost.
Here is my code for the makequiz:
print "<H2>Hello $fullname!</H2><P>"; print start_form (-name=>'makequiz', -method=>'POST', -action=>"http:/ +/ist221.nsm.tridenttech.edu/perl/gradequiz.cgi"); chdir("/perl/web"); open FILE, "$file" || die "Cannot open $file: $!"; while (<FILE>) { # ** READS EACH LINE OF TEXT FROM FILE chomp; # ** BY DEFAULT, CHOMPS OFF $/ F +ROM EACH LINE ($type, $value) = split (/:#\s*/, $_); # ***** SPLITS EACH LIN +E BY TYPE AND CONTENT if ($type =~ m/i/i) { # ** CHECKS FOR IMAGE print "<IMG SRC=http://ist221.tridenttech.edu/images/$courselocation/$ +value>"; print "<P>"; }elsif ($type =~ m/q/i) { # ** CHECKS FOR QUESTION LINE & PRINT +S QUESTION $questionno++; print "<B>$questionno. $value</B><BR>"; push(@allquestions, $value); }elsif ($type =~ m/a/i) { # ** CHECKS FOR ANSWER LINE @answers = split (/`\s*/, $value); $anslength = @answers; # ** LENGTH OF @ANSWERS push(@allanswers, $value); }elsif ($type =~ m/s/i) { # ** CHECKS FOR SELEC +TION LINE $buttonname = $type . $questionno; push(@allselections, $value); %selections = split (/`\s*/, $value); @options = keys (%selections); if ($anslength > 1) { # ** DETERMINE +S TO USE RADIO OR CHECKBOX print "<BR>"; print checkbox_group(-name=>$buttonname, -v +alues=>\@options, -linebreak=>'true', -labels=>\%selections); }else { print "<BR>"; print radio_group(-name=>$buttonname, -values +=>\@options, -linebreak=>'true', -labels=>\%selections, -default=>'-' +); } print "<BR><HR><BR>"; }elsif ($type =~ m/e/i) {# ** CHECKS FOR EXPLAINATION +LINE push (@explain, $questionno, $value); } # END ELSIF STATEMENTS } # ** END WHILE STATEMENT close (FILE); print "<CENTER>"; # ** THIS SECTION SENDS THREE ARRAYS TO THE GRADEQUIZ.CGI print hidden(-name=>"answers", -default=>\@allanswers); print hidden(-name=>"questions", -default=>\@allquestions); print hidden(-name=>"selections", -default=>\@allselections); print hidden(-name=>"explain", -default=>\@explain); print hidden(-name=>'fname', -value=>$fname); print hidden(-name=>'lname', -value=>$lname); print hidden(-name=>'reviewtime', -value=>$reviewtime); print hidden(-name=>'file', -value=>$file); print hidden(-name=>'id', -value=>$idinput); print submit (-value=>'Grade'); print "</CENTER>"; print end_form; } print "The last element in the questions array is $#allquestions<p>"; # ************************* END SUBROUTINE MAKEEXAM print end_html;
janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention
Retitled by davido from 'Unusual problem'.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unusual problem with CGI based quiz
by Ovid (Cardinal) on Jul 06, 2005 at 17:06 UTC | |
|
Re: Unusual problem with CGI based quiz
by cmeyer (Pilgrim) on Jul 06, 2005 at 17:12 UTC | |
by sgifford (Prior) on Jul 06, 2005 at 20:38 UTC | |
by chriso (Sexton) on Jul 07, 2005 at 17:36 UTC | |
by sgifford (Prior) on Jul 07, 2005 at 18:56 UTC | |
|
Re: Unusual problem with CGI based quiz
by chriso (Sexton) on Jul 06, 2005 at 16:58 UTC | |
|
Re: Unusual problem with CGI based quiz
by Anonymous Monk on Jul 07, 2005 at 16:26 UTC |