[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgi-list
Subject:    Re: [CGI] about Multi-input
From:       BTilly () USCCMAIL ! bms ! com
Date:       1998-06-30 19:32:48
[Download RAW message or body]

When you put values into a hash, if you put the same name in
twice it copies over the old value.  This sort of mistake is one
reason why you should use a tested program for retrieving values.

But if you want to do it your way, you can use anonymous arrays
instead of a hash.

@Pairs=map{[split /=/,$_,2]}split /\&/, $ENV{'QUERY_STRING'});

Now $Pairs[$i][0] has the i'th name, and $Pairs[$i][1] has the
corresponding value.

Cheers,
Ben Tilly


______________________________ Reply Separator _________________________________
Subject: [CGI] about Multi-input
Author:  owner-cgi-list@jann.com at Internet/X400
Date:    6/30/98 12:23 PM


(sorry for posting again)

Hi! everybody,

There are some bugs in my script. When I input more than one value,
it can not work properly. For instance, when I choose two names,
aaa and bbb, the output is ' bbb say hello', not ' aaa  bbb say hello'.

Could someone help me to figure out how to fix this problem ?
Thank you very much.

Best Wishes from FCC.

p.s. my script is as follows:
######################################################start
#!/perl/bin/perl

$cgiurl = "http://127.0.0.1/cgi-bin/test.cgi";

print "Content-type: text/html\n\n";

&get_data;
&set_var;

print "<hr>";
print "<font color=red>$name<\/font> say \"hello\"\n";
##########################
sub get_data {
@querys = split(/&/, $ENV{'QUERY_STRING'});
foreach $query (@querys) {
  ($name, $value) = split(/=/, $query);
  $FORM{$name} = $value;
}

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair);
  # Un-Webify plus signs and %-encoding
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value =~ s/<!--(.|\n)*-->//g;
  if ($allow_html != 1) {
     $value =~ s/<([^>]|\n)*>//g;
     $value =~ s/<([^>]|\n)*//g;
  }
  else {
     unless ($name eq 'says') {
            $value =~ s/<([^>]|\n)*>//g;
            $value =~ s/<([^>]|\n)*//g;
     }
  }
  $FORM{$name} = $value;
}
}
#########################################
sub set_var {
if ($FORM{'test'}) {
   $test = "$FORM{'test'}";
}
else {
print "<form method=post action=$cgiurl?name=$name>";
print "Input: <input type=checkbox name='name' value='aaa'>aaa\n";
print "<input type=checkbox name='name' value='bbb'>bbb\n";
print "<input type=checkbox name='name' value='ccc'>ccc\n";
print "<br><input type=submit value='yes'> <input type=reset
value='reset'><\/form>\n";
}
if ($FORM{'name'}) {
   $name = "$FORM{'name'}";
}
else {
exit 0;
}
}
#######################################################end
=================================================
.Fong-Chih Chen@Women's Studies in Manchester
.ADD: 22, Swindon Close, Gorton, Manchester, M18 8JQ, UK
.E-Mail: fcchen@fcc.u-net.com
.FCC WebSite: http://www.fcc.u-net.com/
-----------------------------------------------------------------
For subscription information, http://www.jann.com/lwgate/lwgate.pl/CGI-LIST/.

The CGI Tips & Tricks website (and archive of the list) is located
at http://www.jann.com/Perl/

cgi-list is hosted by Summit Communication Design (http://www.summitdesign.net).

-----------------------------------------------------------------
-----------------------------------------------------------------
For subscription information, http://www.jann.com/lwgate/lwgate.pl/CGI-LIST/.

The CGI Tips & Tricks website (and archive of the list) is located
at http://www.jann.com/Perl/

cgi-list is hosted by Summit Communication Design (http://www.summitdesign.net).
-----------------------------------------------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic