(作业)如何使用来自用户的输入和 cookie 更改 HTML 背景(使用 Perl CGI)?
(Homework) How to change HTML background (with Perl CGI) using input and cookies from user?
除最后一个 CGI 中 HTML 页面的背景颜色外,一切正常。有人可以帮我吗?我很困。不知道为什么背景颜色不会变
这里是HTML:
<table border="2" cellspacing="5" cellpadding="5">
<tr>
<td align="center">Name</td>
<td><input type="text" name="customer" size="15"></td>
</tr>
<tr>
<td align="center">Select Membership Type</td>
<td>
<input type="radio" name="membership" value="0">Life
<input type="radio" name="membership" value="1">Annual
<input type="radio" name="membership" value="2">Free Trial
</td>
</tr>
<tr>
<td align="center">Choose Background Color</td>
<td>
<select name="color">
<option value="ye">Yellow
<option value="cy">Cyan
<option value="ma">Magenta
<option value="wh">White
<option value="pi">Pink
<option value="go">Gold
<option value="pa">PapayaWhip
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Sign Up and Set Options"></td>
</tr>
</table>
</form>
从上面 HTML 保存用户 cookie 的 CGI:
我要使用一个数组来保存成员类型,以及一个散列
使用选项标签属性值作为完整颜色名称的键
my $customer = param('customer');
my $chosen_membership = param('membership');
my $color = param('color');
my @membership_type = ("Life", "Annual", "Free Trial");
my %colors = ("ye" => 'Yellow',
"cy" => 'Cyan',
"ma" => 'Magenta',
"wh" => 'White',
"pi" => 'Pink',
"go" => 'Gold',
"pa" => 'Papayawhip');
my $chosen_color = $colors{$color};
my $mycookie1 = cookie(-name=>'membership',
-value=>$membership_type[$chosen_membership],
-path=>'/',
-expires=>'+7d');
my $mycookie2 = cookie(-name=>'customer',
-value=>$customer,
-path=>'/',
-expires=>'+7d');
my $mycookie3 = cookie(-name=>"color",
-value=>$chosen_color,
-path=>'/',
-expires=>'+7d');
print header(-cookie => [$mycookie1, $mycookie2, $mycookie3]);
print start_html ( -title => 'Assignment 7');
print "Thank you. Your data has been recorded</br>";
print "<a href='test3.cgi'>See member page</a>";
print end_html;
正在读取 cookie 并使用从 HTML 中选择的颜色作为页面的背景颜色
my $membership_name = cookie("membership");
my $customer_name = cookie("customer");
my $color_name = cookie("color");
print header, start_html;
#what the hell, how to change background color??
<body bgcolor="$color_name">;
print "<h2>Welcome back, $membership_name Member $customer_name.</h2>";
print "<h4>Site rather poor, huh? Sorry. We are working on it.</h4>";
print end_html;
<body bgcolor="$color_name">;
您在这里遗漏了 print
和一些引号。我很惊讶这个运行。
你的意思可能是:
print "<body bgcolor='$color_name'>";
除最后一个 CGI 中 HTML 页面的背景颜色外,一切正常。有人可以帮我吗?我很困。不知道为什么背景颜色不会变
这里是HTML:
<table border="2" cellspacing="5" cellpadding="5">
<tr>
<td align="center">Name</td>
<td><input type="text" name="customer" size="15"></td>
</tr>
<tr>
<td align="center">Select Membership Type</td>
<td>
<input type="radio" name="membership" value="0">Life
<input type="radio" name="membership" value="1">Annual
<input type="radio" name="membership" value="2">Free Trial
</td>
</tr>
<tr>
<td align="center">Choose Background Color</td>
<td>
<select name="color">
<option value="ye">Yellow
<option value="cy">Cyan
<option value="ma">Magenta
<option value="wh">White
<option value="pi">Pink
<option value="go">Gold
<option value="pa">PapayaWhip
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Sign Up and Set Options"></td>
</tr>
</table>
</form>
从上面 HTML 保存用户 cookie 的 CGI:
我要使用一个数组来保存成员类型,以及一个散列 使用选项标签属性值作为完整颜色名称的键
my $customer = param('customer');
my $chosen_membership = param('membership');
my $color = param('color');
my @membership_type = ("Life", "Annual", "Free Trial");
my %colors = ("ye" => 'Yellow',
"cy" => 'Cyan',
"ma" => 'Magenta',
"wh" => 'White',
"pi" => 'Pink',
"go" => 'Gold',
"pa" => 'Papayawhip');
my $chosen_color = $colors{$color};
my $mycookie1 = cookie(-name=>'membership',
-value=>$membership_type[$chosen_membership],
-path=>'/',
-expires=>'+7d');
my $mycookie2 = cookie(-name=>'customer',
-value=>$customer,
-path=>'/',
-expires=>'+7d');
my $mycookie3 = cookie(-name=>"color",
-value=>$chosen_color,
-path=>'/',
-expires=>'+7d');
print header(-cookie => [$mycookie1, $mycookie2, $mycookie3]);
print start_html ( -title => 'Assignment 7');
print "Thank you. Your data has been recorded</br>";
print "<a href='test3.cgi'>See member page</a>";
print end_html;
正在读取 cookie 并使用从 HTML 中选择的颜色作为页面的背景颜色
my $membership_name = cookie("membership");
my $customer_name = cookie("customer");
my $color_name = cookie("color");
print header, start_html;
#what the hell, how to change background color??
<body bgcolor="$color_name">;
print "<h2>Welcome back, $membership_name Member $customer_name.</h2>";
print "<h4>Site rather poor, huh? Sorry. We are working on it.</h4>";
print end_html;
<body bgcolor="$color_name">;
您在这里遗漏了 print
和一些引号。我很惊讶这个运行。
你的意思可能是:
print "<body bgcolor='$color_name'>";