【发布时间】:2013-11-27 14:31:13
【问题描述】:
嗨,我是 Perl、CGI 和 HTML 的新手 我正在使用 Linux 并且我的 apache 配置正确。 我有一个简单的程序,它应该询问您的用户名和密码,输入应该来自我的 Perl 脚本使用 perl 中的 CGI 模块生成的 html 文件。然后用户应单击“登录”按钮,此事件应将这些变量发送到另一个 Perl 脚本进行身份验证...我的问题是使用按钮的 onClick 属性发送这些变量。 我看到很多答案说你应该使用“提交”按钮,但我无法让它工作,很多答案说你应该使用 Javascripts,但我也不知道它是如何工作的,请帮忙! 这是我的登录 perl 脚本(Login.plx):
require 'Authentication.plx';
use CGI;
my $q = new CGI;
print $q->header;
print $q->start_html( -title => "Build Server");
print $q->h2("Login page");
print $q->start_form(
-name =>"Login_form",
-method =>"GET"
-action =>"Authentication.plx");
#Create textfield for Username, asigns value to $username
print $q->p("Name:");
print $q->textfield(-name=> 'usernameInput', -value=> 'Ockert', size=>20, -maxlength=>80);
my $username = $q->param('usernameInput');
#Create masked textfield for Password, asigns value to $password
print $q->p("Password:");
print $q->password_field(-name=>'passwordInput', -value=>'starting value',-size=>20,-maxlength=>80);
my $password = $q->param('passwordInput');
$password = crypt($password,12);
#call subAuthentication subroutine
print $q->submit(
-name => "btnLogin",
-value => "Login");
print $q->end_form;
print $q->end_html;
以及subAuthentication脚本(Authentication.plx):
use CGI;
my $q = new CGI;
sub subAuthentication {
my $username = $q->param('$username');
my $password = $q->param('$password');
@return = ("Username not foud","Incorrect password","empty");
open(DATA,"<Users.txt")
or die "Can't open Users.txt";
$oneline = "";
foreach $oneline (<DATA>) {
#print "\nValue of counter is $count\n";
chomp($oneline);
#print "oneline: $oneline\n";
@oneline = split(',', $oneline, 3);
#get administrator or user
$return[2] = $oneline[2];
if ($username eq $oneline[0])
{
$return[0] = "true";
($password eq $oneline[1])? $return[1] = "true" : 0;
last;
}
}
close(DATA);
return @return;
}
请帮忙:)
【问题讨论】:
-
“我看到很多回答说你应该使用‘提交’按钮”——是的,你应该,这正是提交按钮的用途。 ——“但我无法说出来”——你尝试过什么代码来实现这一点? ——“还有很多答案说你应该使用 Javascripts”——这会使事情变得过于复杂,同时降低了可靠性,不要那样做。
-
感谢@Quentin 的帮助!我移动了 start_form 以便表单控件位于表单内......我仍然需要提交按钮的帮助,它没有正确提交表单然后:我如何获取我发送到 Authentication.plx 的变量回到 Login.plx?