【问题标题】:manage forms with Dynamic Fields Group使用动态字段组管理表单
【发布时间】:2016-08-16 09:57:20
【问题描述】:

我有这样的形式。我想添加动态多组文件(用户根据需要创建字段组)...

目前我是这样做的:

<form>

<!-- group fileds 1 -->
<input type="text" id="input1">
<select id="slect1"></select/>

<!-- group fileds 2 -->
<input type="text" id="input2">
<select id="select2"></select/>
.
.
.
<!-- group fileds n -->
<input type="text" id="inputn">
<select id="selectn"></select/>
</form>

但是管理起来很困难,特别是在php服务器中。

你能推荐一个更好的方法吗?

例如,这是我的 idia:

我创建了一个隐藏输入。

通过jquery读取输入并选择,将其转换为长json字符串,并将其写入隐藏输入。

然后在服务器端,我只读取隐藏的输入并解析 json。

看起来很复杂

您如何管理这些类型的表单?

【问题讨论】:

  • 仔细并通过一些练习、反复试验
  • 但说真的,我不确定你在问什么

标签: php html forms


【解决方案1】:

您可以在输入名称之后使用索引。这项工作将在服务器端为您提供一个数组,位于$_POST['input']$_POST['select']

<form method='post' action='sth.php'>

<!-- group fileds 1 -->
<input type="text" name="input[0]">
<select name="select[0]"></select/>

<!-- group fileds 2 -->
<input type="text" name="input[1]">
<select name="select[1]"></select/>

<!-- group fileds 3 -->
<input type="text" name="input[2]">
<select name="select[2]"></select/>

</form>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 2016-12-18
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    相关资源
    最近更新 更多