处理动态表单 [英] Processing Dynamic Form

查看:118
本文介绍了处理动态表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JS动态表单,在那里我可以添加或删除字段:

I've a JS dynamic form, where i can add or remove fields:

Field 1
Field 2
Field 3
Field 4

现在,如果我删除字段2,并添加一个新的领域:

Now if I remove Field 2 and add a new field:

Field 1
Field 3
Field 4
Field 5

我的表单元素中发送此通过Ajax的POST。 我的问题是服务器端PHP处理。我怎么能知道我有多少个字段有$ _ POST数组中和他们有什么证书?我生成唯一的ID使用田+ counterIndex,但下面的例子中,我怎么能看得懂,我一共有4场和2号缺失有哪些?顺便说一句,在窗体中我有太多的静态字段。

I'm sending this through Ajax POST inside a form element. My problem is server side PHP processing. How can I know how many fields I have inside $_POST array and what are their ids? I'm generating unique id using "field" + counterIndex, but following the example how can I be able to understand that I have a total of 4 fields and that number 2 is missing? By the way, inside the form I have static fields too.

推荐答案

这可以通过PHP做的 $ _ POST 本身是一个数组因此可以循环。

This can be done through PHP as $_POST is itself an array thus it can be looped.

我说,你有字段:

<输入名称=DYN [ID1]/>

<输入名称=DYN [ID2]/>

在后端PHP文件,

循环遍历 $ _ POST 如下:

<?php
if (isset($_POST['SUBMIT_BTN'])) {
  if (! empty($_POST['dyn'])) {
    foreach ($_POST['dyn'] as $dyn_id => $dyn_val) {
     // "$dyn_id" is your ID you needed.
    }
  }
}
?>

这篇关于处理动态表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆