带有Perl CGI的复选框 [英] Checkboxes with Perl CGI
本文介绍了带有Perl CGI的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起,如果我的问题太简单,我刚刚开始与CGI ...
所以我有一个相同的名称的复选框。示例HTML:
Sorry if my question is too simple, I am just starting out with CGI... So I have a bunch of checkboxes with the same name. Sample HTML:
<form action="/cgi-bin/checkbox.cgi" method="POST">
<input name="Loc_opt" value="Loc_1" type="checkbox">Option 1<br>
<input name="Loc_opt" value="Loc_2" type="checkbox">Option 2<br>
<input name="Loc_opt" value="Loc_3" type="checkbox">Option 3<br>
<input type="submit" value="Submit">
</form>
我需要找出哪些是使用Perl CGI检查。我在checkbox.cgi中有以下内容:
I need to find out which of them are checked using Perl CGI. I have the following in checkbox.cgi:
print "Content-type:text/html\r\n\r\n";
local ($buffer, @pairs, $pair, $name, $value, %FORM);
# Read in text
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}else {
$buffer = $ENV{'QUERY_STRING'};
}
# Split information into name/value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
现在我应该怎么打印, ?
What should I do to now print, say, the values of the selected checkboxes?
推荐答案
如果您有多个具有相同名称的表单元素,您需要将param CGI101 :
You need to set the param() result into an array if you have multiple form elements with the same name.From CGI101:
my @colors = param('color');
foreach my $color (@colors) {
print "You picked $color.<br>\n";
}
这篇关于带有Perl CGI的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文