简体   繁体   English

使用动态生成的字段(列表)从HTML表单收集数据

[英]Gather data from HTML form with dynamically generated fields (list)

I have a form where I generate a field on button click (fields are identical). 我有一个表单,其中在单击按钮时生成一个字段(字段相同)。

Until now I tried just using unique names for each field but then I can't loop through them because I don't know how many fields I have! 到现在为止,我只尝试为每个字段使用唯一的名称,但是我无法遍历它们,因为我不知道我有多少个字段!

Can I use: 我可以用吗:

<ul>
   <li>
      <select name="personid">
         <options>...</options>
      </select>
      <select name="personid">
         <options>...</options>
      </select>
   </li> 
   <li>
      <select name="personid">
         <options>...</options>
      </select>
      <select name="personid">
         <options>...</options>
      </select>
   </li>
   ... 
</ul>

And then after I post the form loop through the list somehow and access all fields? 然后,我以某种方式通过列表发布表单循环并访问所有字段之后?

Any ideas on how to access the data after I post? 发布后如何访问数据的任何想法?

On your action page, all of the values for the same field name will be separated by commas. 在您的操作页面上,相同字段名称的所有值都将用逗号分隔。 You can loop through them as a simple list. 您可以将它们作为简单的列表进行遍历。 Just make sure your values don't contain commas! 只要确保您的值不包含逗号!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM