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 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决