#create Web page
print "<HTML><HEAD><TITLE>Juniper Printers</TITLE></HEAD>\n";
print "<BODY><H2>\n";
print "Thank you, $name, for completing \n";
print "the registration form.<BR><BR>\n";
print "We have registered your Juniper $models[$modnum] printer, \n";
print "serial number $serial.\n";
print "You indicated that the printer will be used on a \n";
print "$systems{$sysletter} system.<BR><BR>\n";
print "The primary use for this printer is:<BR><BR>\n";
foreach $use (@primary_uses) {
print "$use<BR>\n";
}
print "</H2></BODY></HTML>\n";
Anonymous C replied with this 12 years ago, 2 minutes later, 36 minutes after the original post[^][v]#469,892
@469,883 (A)
It sounds like you need a hash or array that functions as a dictionary structure. Do you intend for the ID-to-label relationship to be exactly one in both directions? If so, you could use this pseudo code…
declare each ID as mapping to a text label
loop over each ID
if the selected options includes this ID
output the text value from the list that is stored at the current ID index
else
debug log that this option was not selected
end
Note that this only outputs predefined, known safe content and does not pass through user submitted content. Also note that this discards and does not loop over user submitted content that might not match the defined criteria. Both of those ate for security and resource efficiency purposes.
(Edited 23 seconds later.)
Meowth replied with this 12 years ago, 1 minute later, 37 minutes after the original post[^][v]#469,895
Anonymous C replied with this 12 years ago, 2 minutes later, 39 minutes after the original post[^][v]#469,898
@469,891 (A)
Please use formatted string interpolation as a basic sanitization method:
sprintf "thank you %s", $name;
Anonymous A (OP) replied with this 12 years ago, 1 minute later, 41 minutes after the original post[^][v]#469,899
@469,892 (C)
Well, the project in my book says it needs an array not a hash. I was thinking I might have needed a hash too.
This is the checkbox list I have to connect the script to.
Anonymous A (OP) double-posted this 12 years ago, 1 minute later, 42 minutes after the original post[^][v]#469,900
@previous (A)
As you can see, the desired effect gets done, but it doesn't display the names Home, Business, Educational, or Other, it just displays the numbers assigned to the array.
Anonymous C replied with this 12 years ago, 32 seconds later, 43 minutes after the original post[^][v]#469,902
array as the user-submitted content. If the param values are the selected IDs, output those labels by referencing the value in the array at the selected index; e.g.
@primary_uses[0];
Anonymous A (OP) replied with this 12 years ago, 3 minutes later, 47 minutes after the original post[^][v]#469,903
@previous (C)
So my @primary_uses[0] = or @primary_uses[0] = param('Use');?
(Edited 45 seconds later.)
Anonymous C replied with this 12 years ago, 1 minute later, 49 minutes after the original post[^][v]#469,904
@previous (A)
I'm providing you with explanations of how to make changes and not literal examples of how your code should read. That example is to tell you that if the user has selected value zero of the list of options, then you should output value zero from your array of options.
Anonymous B replied with this 12 years ago, 3 minutes later, 53 minutes after the original post[^][v]#469,905
@469,903 (A)
Does it work any differently if you ditch the line @primary_uses = param('Use'); altogether?
Anonymous A (OP) replied with this 12 years ago, 14 minutes later, 1 hour after the original post[^][v]#469,912
@previous (B)
Yes, it just displays all four options. I assume this is because the script isn't connected to the html form tags, right?
Anonymous B replied with this 12 years ago, 13 minutes later, 1 hour after the original post[^][v]#469,913
@previous (A) > Yes, it just displays all four options.
But it' displaying the names you put in the array now, not numbers? What's changing when you assign the user submitted content to that array?
(Edited 17 seconds later.)
Anonymous C replied with this 12 years ago, 11 minutes later, 1 hour after the original post[^][v]#469,924
@previous (B)
The user submitted values appear to be the array indices of the selected checkboxes.
(Edited 9 seconds later.)
Anonymous A (OP) replied with this 12 years ago, 1 minute later, 1 hour after the original post[^][v]#469,926
I figured out. I just used a $key command and assigned array @use to param('Use');
My revised code:
#declare variables
my ($name, $serial, $modnum, $sysletter, $key, @use);
my @models = ("Laser JX", "Laser PL", "ColorPrint XL");
my %systems = ("W", "Windows",
"M", "Macintosh",
"U", "UNIX");
my @uses = ("Home", "Business", "Educational", "Other");
#create Web page
print "<HTML><HEAD><TITLE>Juniper Printers</TITLE></HEAD>\n";
print "<BODY><H2>\n";
print "Thank you, $name, for completing \n";
print "the registration form.<BR><BR>\n";
print "We have registered your Juniper $models[$modnum] printer, \n";
print "serial number $serial.\n";
print "You indicated that the printer will be used on a \n";
print "$systems{$sysletter} system.<BR><BR>\n";
print "The primary use for this printer is:<BR><BR>\n";
foreach $key (@use) {
print "$uses[$key]<BR>\n";
}
print "</H2></BODY></HTML>\n";
Anonymous B replied with this 12 years ago, 5 minutes later, 1 hour after the original post[^][v]#469,928