【问题标题】:Perl CGI, Multiple forms and multiple submit button with action on the same pagePerl CGI,多个表单和多个提交按钮,在同一页面上执行操作
【发布时间】:2016-12-04 11:14:59
【问题描述】:

鉴于我有多个按钮并且“action=”也在同一页面上,我如何指定在我的 Perl CGI HTML 输出中点击多个按钮之一所采取的操作?

这是 html 输出,按钮(流程活动和重复记录)正常工作,但“导入信息”(我正在尝试实现)调用“流程活动”

这里是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";

picture of button layout

我相信这是被调用的形式:

 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++;
 }

}

我知道这很长,如果我能得到任何反馈,我将不胜感激。我可以根据需要发布其他信息。再次感谢。

【问题讨论】:

  • 我希望这能进一步澄清我的问题。我希望在按下“流程活动”后找出流程序列的去向?任何提示都非常感谢

标签: javascript html forms perl cgi


【解决方案1】:

给所有submit按钮唯一的name属性,提交数据将只有一个submit参数,即被点击的那个。通过检查他们的names 并相应地处理来找出它是什么。下面给出了一些示例代码。

客户端:

<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
}

【讨论】:

    猜你喜欢
    • 2012-06-07
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    相关资源
    最近更新 更多