所以我在这里要做的是为网页构建一对。所以有主页(比如m1)。所以 m1 只有一个输入字段和一个提交按钮。所以我想做的是从主页的输入字段中获取变量(一个字符串),然后将它与一组字符串进行比较,然后重定向到相应的网页。例如,如果我在输入字段中输入“蓝色”,它应该取值,将其与一组值进行比较并重定向到相应的网页(可能是蓝色背景的页面)
这是我正在尝试使用的代码,经过长时间的搜索后得到的。
use CGI qw/:standard :html3/;
# this defines the contents of the fill out forms
# on each page.
@PAGES = ('Main','Blue','Red','Yellow','Green');
%FIELDS = ('Main' => ['Name'],
);
# accumulate the field names into %ALL_FIELDS;
foreach (values %FIELDS) {
grep($ALL_FIELDS{$_}++,@$_);
}
# figure out what page we're on and where we're heading.
$current_page = calculate_page(param('page'),param('go'));
$page_name = $PAGES[$current_page];
print_header();
print_form($current_page) if $FIELDS{$page_name};
print_review($current_page) if $page_name eq 'Review';
print_confirmation($current_page) if $page_name eq 'Confirmation';
print end_html;
# CALCULATE THE CURRENT PAGE
sub calculate_page {
my ($prev,$dir) = @_;
return 0 if $prev eq ''; # start with first page
return $prev + 1 if $dir eq 'Submit Application';
return $prev + 1 if $dir eq 'Next Page';
return $prev - 1 if $dir eq 'Previous Page';
}
# PRINT HTTP AND HTML HEADERS
sub print_header {
print header,
start_html("Your Friendly Family Loan Center"),
h1("Your Friendly Family Loan Center"),
h2($page_name);
}
# PRINT ONE OF THE QUESTIONNAIRE PAGES
sub print_form {
my $current_page = shift;
print "Please enter the name",
start_form,
hr;
draw_form(@{$FIELDS{$page_name}});
print hr;
print submit(-name=>'go',-value=>'Previous Page')
if $current_page > 0;
print submit(-name=>'go',-value=>'Submit'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}
我的问题是如何访问第一页中提交的变量以及如何与变量集进行比较?当我说变量集时,它表示一个数组,其值为红色蓝色绿色黄色