Yes, that is exactly what I am attempting to do. Dealing with an array is what I am familiar with though I should read up on array references.
How would I build an array of the data?
Thanks for the path to wisdom hippo.
| [reply] |
The problem with multiple values in an array is that a checkbox field will not exist in the values sent by the form unless it is checked. In your example, if you kept the names the same and only one checkbox was ticked it would come in like this:
Professor => ["Doe, Jane","Smith, Josh"],
IDNum => ["0116411160645","0116411162016"],
Status => "KEEP THIS ITEM",
You have no way of telling which item this refers to. So you will need to group each item somehow, and I think your idea of incrementing is fine, as long as you do it to all parameters as hippo points out. | [reply] [d/l] |
Excellent point. The easy alternative is to replace the checkboxes with selects which just have "Yes" and "No" as options. Not as clean from a UI point of view, though.
Yet another option is to set the values of the checkboxes to a unique identifier like the IDNum (assuming it is unique) and that way you know which ones are to be kept.
There's also the JS option, but I like that least of all.
TIMTOWTDI!
| [reply] |
Thanks everyone for the help and great information. The modules mentioned look promising, sadly they are not on installed on my system. Going to code it the long way as your right, I won't know which books have been checked.
| [reply] |
| [reply] |
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI::Lite ();
print "Content-type: text/plain\n\n";
my $cgi = CGI::Lite->new ();
my $params = $cgi->parse_form_data;
my $i = 0;
while ($i <= $#{$params->{Professor}}) {
print "Professor $i is $params->{Professor}->[$i]\n";
print "IDNum $i is $params->{IDNum}->[$i]\n";
# ... carry on with other fields here
$i++;
}
Update: See also the get_multiple_values convenience method in the documentation which is a benefit if you don't know for sure that there will be more than one of each item. | [reply] [d/l] [select] |