如果我有几个按钮并且“action =”也在同一页面上,如何指定在我的Perl CGI HTML输出上的多个按钮之一上执行哪个操作?
这是html输出和按钮(Process Activity和Duplicate record)正常工作,但是“Import Info”(我正在尝试实现)调用“Process Activity”
这是java脚本代码:
<script type="text/javascript" src="$HostedSiteURL/$ScriptDirectory/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
\$(document).ready(function() {
\$('#importFromCAD').click(function () {
\$('#importNav').val('');
return true;
\$('#process-activity').click(function () {
\$('#DupNav').val('');
return true;
});
Perl CGI HTML代码:
sub NewRightSide
{
print " <div style=\"z-index:86;\" class=\"group-shell\">";
print " <table>\n";
print " <tr><td><input class=\"dial-red-button\" id=\"importFromCAD\" type=\"submit\" value=\"Import Info\"></td></tr>\n";
print " <tr><td><input class=\"dial-red-button\" id=\"process-activity\" type=\"submit\" value=\"Process Activity\"></td></tr>\n";
print " <tr><td><input class=\"dial-red-button\" id=\"duplicate-record\" type=\"submit\" value=\"Duplicate Record\"></td></tr>\n";
我相信这是被称为的形式:
print "<form name=\"form\" accept-charset=\"utf-8\" method=\"post\" action=\"A_CT_DIAL8.pl\">\n";
if ($Nav eq "" || $Nav eq "None") {$Nav="NewEntry";}
print "<input type=\"hidden\" name=\"s\" value=\"$escape_session\" />\n";
print "<input type=\"hidden\" name=\"nav\" value=\"DIAL\" id=\"nav\">\n";
print "<input type=\"hidden\" name=\"Nav\" value=\"$Nav\" id=\"Nav\">\n";
print "<input type=\"hidden\" name=\"SubNav\" value=\"$SubNav\">\n";
print "<input type=\"hidden\" name=\"DupNav\" value=\"\" id=\"DupNav\">\n";
print "<input type=\"hidden\" name=\"nav_tab\" value=\"\" id=\"nav_tab\">\n";
print "<input type=\"hidden\" name=\"Report\" value=\"\" id=\"Report\">\n";
print "<input type=\"hidden\" name=\"TransLimit\" value=\"$TransLimit\">\n";
这是名为“DupNav”的Perl子例程,我不确定它在表单的功能方面起作用。这是子程序第二个.click(function ())
类吗?
if ($DupNav eq "")
{
$Nav = ""; $KeyField = ""; # $CAD = "";
$In = ""; $Out = ""; $Via = "";
$Status = ""; $Device = ""; $ActivitySubject = "";
$Memo = ""; $currenttime = ""; $NormalMemo = "";
$CheckNewMemo = ""; $PostMile = "";
}
else
{
$CheckRadio="No";
if ($DupWarn ne "Off")
{
$JavaWarn=$JavaWarn."Duplicated Last Entry. ";
$Warn=$Warn." [ Duplicated Last Entry ]";
$SubNav="Go";
}
else
{
$JavaWarn=$JavaWarn."Use the Duplicate Record button to pre fill the next entry with the same information as the last entry. ";
$Warn=$OldWarn." [ Use the Duplicate Record button to pre fill the next entry with the same information as the last entry ]";
}
}
if ($Device == 0) {$Device="";}
$currentdate = "";
$SplitMemo=$CheckNewMemo;
@GetEntries=split(":DOSEP:", $SplitMemo);
$EntryCount=@GetEntries;
$Memo=$GetEntries[0];
$b=1;
while ($b < $EntryCount)
{
$SplitExtras=$GetEntries[$b];
@GetExtras=split(":", $SplitExtras);
$ExtraListName=$GetExtras[0];
$ExtraListInfo=$GetExtras[1];
if ($ExtraListName eq "PostMile") {$PostMile=$ExtraListInfo; $DisablePostMileSection="No";}else{$Extra_Information{$ExtraListName}="$ExtraLis tInfo";}
$b++;
}
}
我知道这很长,我真的很感激我能得到的任何反馈。我可以根据需要发布其他信息。再次感谢你。
答案 0 :(得分:1)
为您的所有submit
按钮提供唯一name
个属性,提交数据只有一个submit
参数,即被点击的参数。通过检查他们的name
并相应地处理它来找出它是什么。下面给出了一些示例代码。
客户端:
<form method="POST" action="/act">
<input name="formid" value="1" type="hidden">
<input class="delete" value="D" name="delete" type="submit">
<input class="edit" value="E" name="edit" type="submit">
</form>
服务器端:
if ( defined param('edit')) {
# perhaps identify form by some checking for some hidden element
# process the data for edit
}
elsif ( defined param('delete') ) {
# perhaps identify form and process the data for delete
}