我有两个文件login.pl和index.html。我试图从login.pl中获取用户的输入并将其发送到index.html,以便显示用户的姓名和时间。我被告知这样做我需要使用HTML:模板,我查看了关于CPAN的教程,但是他们有一个非常简单的例子并没有真正帮助。此外,我不能让标量(本地时间)在html文件中工作,因为它是一个cgi函数。我将在下面发布这两个文件的代码,有人可以告诉我我做错了什么以及如何解决它?
login.pl
#!/usr/bin/perl -wT
use strict;
use HTML::Template;
use CGI qw(:standard);
my $template = HTML::Template->new( filename => 'dashboard.html' );
my %names = map { $_ => 1 } param;
my $open = "1234";
sub windowLayout() {
return (
header,
start_html("Input Form"),
start_form,
"Please enter your username:",
textfield( -name => 'username', -maxlength => 20 ),
p,
"Please enter your password:",
password_field( -name => 'password', -maxlength => 20 ),
p, submit,
hr;
);
}
if ( $names{username} and $names{password} ) {
my $username = param("username");
my $password = param("password");
$template->param( USERNAME => $ENV{"username"} );
if ( $password ne $open ) {
print
windowLayout(),
end_form,
p( { -style => 'Color: red;' }, "Sorry wrong password!" );
print end_html;
} else {
print "Content-Type: text/html\n\n", $template->output;
#print redirect("index.html");
}
} else {
print
windowLayout(),
end_html;
}
dashbooard.pl
<!DOCTYPE>
<html>
<head><title>Testing</title></head>
<body>
My user name is: <TMPL_VAR NAME=USERNAME>
The time is now: #have no idea how to get scalar(localtime) in HTML
</body>
</html
编辑:
我收到此输出,看起来我仍然在login.pl
我的用户名是:现在是时候:
编辑2:
$ in $ template-&gt;输出中的Pun;