|
| Hello all,
I'm designing a survey which begins with a list of services as shown in
http://www.open365test.net/Survey.html
Users would enter their ID, check one or more services and click
submit. Then, they are presented with a list of identical questions for
each service chosen. The interface I have designed uses a foreach loop
to go through each of the services chosen (and not chosen services'
responses are passed as hidden inputs with NA value)..hence user will
be submitting just one form; however this form can potentially be very
long - in my actual example, I have 12 initial checkboxes, and 20
identical set of questions.
I was wondering if anyone can help me modify the script below so to
present 1 selected service at a time with a submit button..which when
invoked writes the response to a temp file. Then 2nd selected service
is presented and its response gets appended to the temp file. Finally
after the last selected service's response is appended to the temp
file, this temp file would be inserted as a record in the master log
file.
I don't know how to break this long survey into multiple (identical)
chunks and would greatly appreciate any help or guidance.
Thank you for your time.
Best regards,
Shree
--------script to present set of identical questions-------
#!/usr/bin/perl -w
# script name - Survey-Start.cgi
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $EID = param("EID");
my @Q1_Services_Chosen = param("Q1_Services");
sort {$a cmp $b} (@Q1_Services_Chosen);
my @Q1_Services_All = ("Laptop", "Desktop", "Server", "PDA");
sort {$a cmp $b} (@Q1_Services_All);
sub intersets {
my ($a, $b) = @_;
my (%ah, %bh);
@ah{ @$a } = @$a;
@bh{ @$b } = ();
delete @bh{ @$a };
( [ keys %ah, keys %bh ], [ grep defined, delete @ah{ @$b } ],
[ keys %ah ], [ keys %bh ] )
}
my($mrg, $common, $a, $b) = intersets(\@Q1_Services_All,
\@Q1_Services_Chosen);
my @Q1_Services_NotChosen = @$a;
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head> \n";
print "<title>Survey Start</title>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\">\n";
print "</head> \n";
print " <body onLoad=\"self.focus()\" >\n";
print "<br>\n";
print "<h1><font size=\"5\">Survey Form</font></h1>\n";
print "<b>$EID</b> you chose @Q1_Services_Chosen<br>\n";
print "<b>$EID</b> you did not choose @Q1_Services_NotChosen<br>\n";
print "<form name = \"Survey\" action = \"/cgi-bin/Survey-Submit.cgi\"
method=\"post\">\n";
print "<INPUT type=hidden name=\"EID\" value=$EID >\n";
my ($chosen_service, $not_chosen_service) = "";
foreach $chosen_service (@Q1_Services_Chosen) {
print "Section for <b>$chosen_service</b><br>\n";
print "Q2 How satisified are you with services provided for
$chosen_service:\n";
print "<INPUT type=radio name=\"Q2_$chosen_service\" value=\"1\"
>|\n";
print "<INPUT type=radio name=\"Q2_$chosen_service\" value=\"2\"
>|\n";
print "<INPUT type=radio name=\"Q2_$chosen_service\" value=\"3\"
>|\n";
print "<INPUT type=radio name=\"Q2_$chosen_service\" value=\"4\"
><br>\n";
print "Q3 How important is the service provided for
$chosen_service:\n";
print "<INPUT type=radio name=\"Q3_$chosen_service\" value=\"1\"
>|\n";
print "<INPUT type=radio name=\"Q3_$chosen_service\" value=\"2\"
>|\n";
print "<INPUT type=radio name=\"Q3_$chosen_service\" value=\"3\"
>|\n";
print "<INPUT type=radio name=\"Q3_$chosen_service\" value=\"4\"
><br><hr>\n";
}
print "Please enter any other comment <INPUT TYPE=\"text\"
NAME=\"Comment\" SIZE=\"20\" value = \"\"><br>\n";
foreach $not_chosen_service (@Q1_Services_NotChosen) {
print "<INPUT type=hidden name=\"Q2_$not_chosen_service\" value=\"NA\"
>\n";
print "<INPUT type=hidden name=\"Q3_$not_chosen_service\" value=\"NA\"
>\n";
}
print "<input type=\"submit\" NAME=\"submit\" value=\"submit\">\n";
print "</form>\n";
print "</body> \n";
print "</html> \n";
--------script to record response to the master log file -------
#!/usr/bin/perl -w
# script name - Survey-Submit.cgi
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $EID = param("EID");
my $Q2_Laptop = param("Q2_Laptop");
my $Q3_Laptop = param("Q3_Laptop");
my $Q2_Desktop = param("Q2_Desktop");
my $Q3_Desktop = param("Q3_Desktop");
my $Q2_Server = param("Q2_Server");
my $Q3_Server = param("Q3_Server");
my $Q2_PDA = param("Q2_PDA");
my $Q3_PDA = param("Q3_PDA");
my $FileOut = "Survey.txt";
open (FILEOUT, ">>$FileOut") or die "Cant open FILEOUT $FileOut $!";
flock (FILEOUT, 2);
print FILEOUT
" $EID|$Q2_Laptop|$Q3_Laptop|$Q2_Desktop|$
Q3_Desktop|$Q2_Server|$Q3_Server|$Q2_PDA
|$Q3_PDA\n";
close (FILEOUT);
print header ();
print <<END_HTML;
<HTML>
<HEAD>
<TITLE>Survey Submit</TITLE>
</HEAD>
<BODY>
Thank you for taking the survey
</BODY>
</HTML>
END_HTML
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
|
|