我使用jquery在我的页面上添加动态输入。我最初只想显示一个输入,然后单击一个按钮可以添加更多输入。
这按预期工作。
然后我使用php来捕获
$_POST
输入值并将其发送到外部脚本。这同样有效,但是我总是在数组中收到一个额外的项目,而且它是空的。
我想这是因为我隐藏了
“我的HTML”中的字段,在生成新输入时显示该字段?
我的代码如下;
HTML
// unnecessary code removed
JQuery
$(document).ready(function() {
//here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.
$(".add-more").click(function() {
var html = $(".copy-fields").html();
$(".after-add-more").after(html);
});
//here it will remove the current value of the remove button which has been pressed
$("body").on("click", ".remove", function() {
$(this).parents(".control-group").remove();
});
});
PHP
// unnecessary code removed
$field_values_array = $_POST['addmore'];
?>
在不生成额外输入的情况下,我输入
1111111
输入框并提交。一
print_r($_POST)
生产;
[addmore] => Array
(
[0] => 1111111
[1] =>
)
感谢您的帮助。