【发布时间】:2014-06-27 16:12:00
【问题描述】:
提问前的几点说明: 我绝不是程序员,但我的任务是让它工作。我知道非常基础的知识以及如何改变之前涉足的一些事情,但这就是我的技能组合的终点。 我对此进行了编辑以节省空间并使其尽可能简单。 我知道这个 perl 脚本很旧,但这是我必须使用的。
我在 HTML 页面上有一个表单,其中包含以下选项:
<form action="/cgi-bin/form.pl" method="post" name="form">
<input type="checkbox" name="morning_class" value="name1">
<select name="Priority"><option value="">--Select--</option><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input type="checkbox" name="morning_class" value="name2">
<select name="Priority"><option value="">--Select--</option><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input type="checkbox" name="morning_class" value="name3">
<select name="Priority"><option value="">--Select--</option><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input type="checkbox" name="morning_class" value="name4">
<select name="Priority"><option value="">--Select--</option><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<input type="checkbox" name="morning_class" value="name5">
<select name="Priority"><option value="">--Select--</option><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<p><label class="field_pledge" for="fname">First Name:</label> <input maxlength="50" name="First_Name" size="32" type="text"></p>
<p><label class="field_pledge" for="lname">Last Name:</label> <input maxlength="50" name="Last_Name" size="32" type="text"></p>
<p><label class="field_pledge" for="email">EMail:</label> <input name="Email" size="32" type="text"></p>
<p><input type="submit" value="Submit"> <input type="reset" value="Clear Form"></p>
</form>
我需要限制用户必须从顶部的复选框中准确选择 3 个选项。然后,他们必须按照 1-3 的顺序列出他们想要参加的早课的优先选项(这是出于日程安排的原因)。
目前,Perl 脚本如下(正如我上面提到的,我知道这是一个旧脚本,但我坚持使用它,因为这是给我的,我不是程序员) :
#!/usr/bin/perl
#Variables
$queryString;
$contentLength;
$number;
$sendmail="/usr/sbin/sendmail";
@testarray;
%testhash;
$contentLength = $ENV{"CONTENT_LENGTH"};
$return = "/thankyou/";
if($contentLength != NULL){
read(STDIN, $queryString, $contentLength);
}
@testarray = split(/&|=/,$queryString);
$number = @testarray;
for ($counter = 0; $counter <= $number; $counter++){
@testarray[$counter] =~ s/\+/ /g;
@testarray[$counter] =~ s/%([0-9A-Fa-f]{2})/pack("c",hex($1))/ge;
}
%testhash = @testarray;
##MESSAGE FORMATTING
$finalmailbody = "Title of Email - Registration Form\n\n";
$finalmailbody .= "First Name: $testhash{First_Name}\n";
$finalmailbody .= "Last Name: $testhash{Last_Name}\n";
$finalmailbody .= "Email: $testhash{Email}\n";
##OPEN EMAIL AND SEND
open(MAILREGISTRATION, "|$sendmail -oi -t") || die "Can't open pipe to $sendmail: $!\n";
print MAILREGISTRATION "To: me\@mywebsite.com\n";
print MAILREGISTRATION "From: $testhash{Email}\n";
print MAILREGISTRATION "Subject: Conference Submission\n\n";
print MAILREGISTRATION "$finalmailbody";
close(MAILREGISTRATION) or die "Can't close pipe to $sendmail: $!\n";
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print " <META HTTP-EQUIV=Refresh CONTENT=0;URL=$return>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "</BODY>\n";
print "</HTML>\n";
所以,目前,一旦提交,我会收到以下电子邮件:
名字:(输入的信息)
姓:(已输入信息)
电子邮件:(已输入信息)
他们输入数据的部分不是问题。我知道如何更改这些行并在需要时添加更多内容。
这是我的问题发生的地方:
如果我要像这样在消息格式中创建一行:
$finalmailbody .= "Course 1: $testhash{morning_class}\n";
$finalmailbody .= "Course 2: $testhash{morning_class}\n";
$finalmailbody .= "Course 3: $testhash{morning_class}\n";
它所做的只是通过电子邮件发送最后选择的课程,如下所示:
课程 1:名称 3
课程 2:名称 3
课程 3:名称 3
现在我知道需要在 Perl 脚本中放置某种代码来对从 (name=morning_class) 数据中接收到的数据进行排序,但这是我的知识限制我进一步研究的地方。
我最终想要的是显示发送给我的电子邮件:
课程 1: 名称1 优先级: 3
课程 2: 名称2 优先级: 1
课程 3: 名称3 优先级: 2
名字:(已输入信息)
姓氏:(已输入信息)
电子邮件:(已输入信息)
Perl 部分对我来说是最重要的。
如果可以解决这个问题,那么我愿意接受有关如何将选择限制为不超过或少于 3 个的建议(我目前有一些东西,但如果有更好的方法,我希望看到它),以及如何将要在电子邮件中发送的优先级列表与选中的复选框联系起来。
如果还有其他问题需要回答,请告诉我,我会尽我所能解决。
我需要我能提供的所有帮助,所以希望这里有人会很棒并帮助我。 提前致谢!
【问题讨论】:
标签: html forms perl email checkbox