duanjian9148 2016-04-22 16:53
浏览 63
已采纳

使用动态字段组管理表单

I have form like this. I want add dynamic multi group fileds (user create fields groups if needs)...

currently I do it this way:

<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>

But manage is hard,specially in php server.

can you recommend me a better way?

for example this is my idia:

I create one hidden input.

read input&select via jquery,convert it to a long json string,and write it to hidden input.

then in server side, I only read that hidden input and parse json.

it seems complex

how do you manage these type of forms?

  • 写回答

1条回答 默认 最新

  • douchongzhang9267 2016-04-22 16:57
    关注

    You can use indexes after inputs' names. This work will give you an array at the server side, in $_POST['input'] and $_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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab