PHP处理动态多表单POST方法值

时间:2014-02-27 18:04:10

标签: php jquery html forms

我有jQuery提交'N'个表单。现在我需要根据组件数量读取POST值。任何人都可以建议读取所有POST值的代码吗? 特别是我想阅读approve1approve2 ...

注意:当我点击提交时,所有这些不同的表单值都会提交给submit.php 页

我的表格:

<form name="f1" action="submit.php" method=POST>
<input type="hidden" name="approve1" value="93545" />
<input type="submit" value="Submit/>
</form>

<form name="f2" action="submit.php" method=POST>
<input type="hidden" name="approve2" value="93545" />
<input type="submit" value="Submit/>
</form>

.....

<input type="button" value="Submit All"/>

jQuery的:

$(function() {
    $("#submitAll").click(function(ev) {
        ev.preventDefault();
        var newForm = $("<form action='submit.php' method='POST'></form>");
        $("form input[type='hidden']").each(function(i, e) {
            newForm.append(
                $("<input type='hidden' />")
                    .attr("name", e.name)
                    .attr("value", e.value)
            );
        });
        $(document.body).append(newForm);
        newForm.submit();
    });
});

foreach($_POST as $name => $value)仅发布此示例中的最后一个表单值i.e approve2 value

1 个答案:

答案 0 :(得分:1)

foreach($_POST as $name => $value) {
  // Here you have access to parameter names and their values
  echo "<p>name is $name and value is $value</p>";
}