-1

我在模板工具包文件中有代码:

<html>
 <head>
<title>test</title>
<script type="text/javascript">
var counter = 0;
function addNew() {
// Get the main Div in which all the other divs will be added
var mainContainer = document.getElementById('mainContainer');
// Create a new div for holding text and button input elements
var newDiv = document.createElement('div');
// Create a new text input
var newText = document.createElement('input');
newText.type = "input";
//newText.value = counter;
// Create a new button input
var newDelButton = document.createElement('input');
newDelButton.type = "button";
newDelButton.value = "Delete";
// Append new text input to the newDiv
newDiv.appendChild(newText);
// Append new button input to the newDiv
newDiv.appendChild(newDelButton);
// Append newDiv input to the mainContainer div
mainContainer.appendChild(newDiv);
// counter++;
// Add a handler to button for deleting the newDiv from the mainContainer
newDelButton.onclick = function() {
mainContainer.removeChild(newDiv);
}
}
</script>
</head>

<body >
<form name="group_save" method="post" action="process.cgi">
<div id="mainContainer">
<div><input type="button" value="Add" onClick="addNew()"></div>
</div>
 <div><input type = "submit" value = "Save"></div>
</form>
</body>
</html>

我想将文本框的值传递给 cgi 文件 process.cgi 以将其插入数据库。

process.cgi 中的代码:

my $grupsave = $cgi->param("group_save");
if ($grupsave =~ /^([-\@\w.]+)$/) {
    $grupsave = $1;
} else {
    die "Bad data for OS('$grupsave') in group";
}

if($grupsave ne '')  {
    my $grupsave_insert = $dbh->do (q{INSERT INTO group_management  (group_name,group_description,isactive) VALUES (?,?,?)}, undef, ($grupsave,'','y'));
} else {
}

但是在检查时,我发现该值没有进入流程页面。请帮我解决这个问题。

4

1 回答 1

1

您可以使用以下代码获取参数:

my $grupsave = $cgi->param("group_save");

但是您的表单中没有名为“group_save”的 HTML 输入。您使用 Javascript 创建的文本输入没有名称,因此其内容不会传递给您的 CGI 程序。

您需要将文本框命名为“group_save”。

于 2013-06-27T09:42:23.110 回答