简体   繁体   English

Perl CGI,多个表单和多个提交按钮,在同一页面上有操作

[英]Perl CGI, Multiple forms and multiple submit button with action on the same page

How do I specify which action is taken hitting one of the multiple buttons on my Perl CGI HTML output given I have several buttons and "action=" is also on the same page? 如果我有多个按钮,并且在同一页面上也有“ action =”,那么如何指定要在Perl CGI HTML输出上的多个按钮之一上击打哪个动作?

This is the html output and the buttons(Process Activity and Duplicate record) work correctly but "Import Info"(which I'm trying to implement) calls the "Process Activity" 这是html输出,按钮(Process Activity和Duplicate record)可以正常工作,但是“ Import Info”(我正在尝试实现)称为“ Process Activity”

here is the java-script code: 这是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;
});

And the Perl CGI HTML Code: 和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 按钮布局的图片

I believe this is the form which gets called: 我相信这就是所谓的形式:

 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"; 

This is the Perl Subroutine called "DupNav" which I'm not sure it plays a role in how the form functions. 这是称为“ DupNav”的Perl子例程,我不确定它是否在表单的功能中起作用。 Is this the subroutine the second .click(function ()) class? 这是第二个.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++;
 }

}

I know this is very long and I'd really appreciate any feedback I can get. 我知道这很长,我非常感谢收到的任何反馈。 I can post additional information as required. 我可以根据需要发布其他信息。 Thank you again. 再次感谢你。

Give all your submit buttons unique name attributes, the submission data will have only one submit parameter, the one that was clicked. 为所有submit按钮提供唯一的name属性,提交数据将只有一个submit参数,即被单击的一个。 Find out what it is by checking for their name s and process accordingly. 通过检查其name找出其含义并进行相应处理。 Some example code is given below. 下面给出一些示例代码。

Client Side: 客户端:

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

Server Side: 服务器端:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM