|
Question: I am trying to control the order of the output of the
form. I thought that the output would show up in the same order as the form that
I create, but it seems to show up in a random order. Is there any way to control
the order in which each field appears in the email that is generated by the
form?
Answer: You can order the
output sorted by field name. Change the following code.
Original code
sub check_fields{
my $error;
my $line;
foreach $line(keys %IN){
if ($line ne "submit"){
if (($IN{$line} eq "NO") or ($IN{$line} eq "")){
New Code
sub check_fields{
my $error;
my $line;
my @list = sort {uc($a) cmp uc($b)}(keys %IN);
foreach $line (@list){
if ($line ne "submit"){
if (($IN{$line} eq "NO") or ($IN{$line} eq "")){
More sort options (replace the blue line of
code above):
my @list = sort {uc($a) cmp uc($b)}(keys %IN); #->
Alpha ascending, ignore case
my @list = sort {uc($b) cmp uc($a)}(keys %IN); #-> Alpha, descending, ignore
case
my @list = sort {($a) cmp ($b)}(keys %IN); #-> Alpha,
ascending, case sensitive
my @list = sort {$a <=> $b}(keys %IN);
#-> Numeric sort, ascending
|