问题描述
我的表单看起来像这样:
I have a form that looks like so:
<label for="fullpath"><span class="required">*Full Path of folder to change access:</span></label>
<input name="fullpath" id="it10" type="text" size="50" maxlength="50" />
<br />
<small>Example: g:\A\Folder or j:\Your\Folder</small><br />
<div class="bgdiff">
<label for="userpermissiongroup">User Permission Group to be changed:</label>
<input name="userpermissiongroup" type="text" id="it11" size="50" maxlength="50" />
<small>If Known...</small></div>
<br />
<label for="addreadaccess">Additional users requiring read access:</label>
<input name="addreadaccess" type="text" id="it12" size="15" maxlength="15" />
<br />
<small>AD Username</small><br />
<div class="bgdiff">
<label for="addauthoraccess">Additional users requiring author access:</label>
<input name="addauthoraccess" type="text" id="it13" size="12" maxlength="12" />
<br />
<small>AD Username</small></div>
<br />
<label for="removeaccess">Users to be removed from access:</label>
<input name="removeaccess" type="text" id="it14" size="12" maxlength="12" />
<br />
<small>AD Username</small><br />
<div class="bgdiff">
<label for="supervisor"><span class="required">*Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes:</span></label>
<input name="supervisor" type="text" id="it15" size="30" maxlength="30" />
<br />
<small>AD Username</small></div>
<br/>
<label for="phoneapprover"><span class="required">*Phone number of approving official: </span></label>
<input name="phoneapprover" type="text" id="it16" size="30" maxlength="30" />
<br />
<small>999-999-9999</small><br />
</fieldset>
</div>
我想让用户可以选择将所有这些信息添加到此表单中超过1倍提交。 (比如说最多10倍)我的脑子里有几个想法。 1使用Javascript创建新字段,然后用我的PHP脚本以某种方式解析它们。 2就像代码中的上述表单一样,将10个代码剪切并隐藏起来,直到用户点击ADD ANOTHER。
I would like to give users the option to add all of this info to this form more than 1x before submitting. (say 10x max) I have run a couple ideas through my head. 1 is using Javascript to create the new fields and then parse them with my php script somehow. 2 is put say 10 code snips just like the form above in the code and hide them until the user clicks ADD ANOTHER.
每个输入都需要是唯一的,因为我正在提交这个信息想到了一个简单的$ _REQUEST php脚本。我知道如何使用1个输入和每个循环执行此操作,但我不确定如何使用如此大量的输入,标签等...
Each input needs to be unique as I am submitting this info thought a simple $_REQUEST php script. I understand how to do this with 1 input and a for each loop, but am not sure how to make it work with such a large amount of inputs, labels, etc...
<?php
foreach($_POST['newdata'] as $value) {
echo "$value <br />";
}
?>
任何人都有一些关于最佳方式的建议吗?我不确定通过JS添加他的表单是最好的主意,所以只显示隐藏div中的新信息似乎更快更容易...
Anyone have some suggestions on the best way to go about this? I am not sure adding his form via JS is the best idea, so just displaying the new info from a hidden div seems quicker and easier...
推荐答案
如果将 []
附加到表单字段名称,PHP将获取这些字段并将它们转换为数组,例如
If you append []
to your form field names, PHP will take those fields and turn them into an array, e.g.
<input type="text" name="field[]" value="first" />
<input type="text" name="field[]" value="second" />
<input type="text" name="field[]" value="third" />
会产生以下$ _POST结构:
would produce the following $_POST structure:
$_POST = array(
'field' => array(
0 => 'first',
1 => 'second',
2 => 'third',
)
);
另一种方法是将递增数字附加到每个字段名称,因为复制每个字段的现有字段集新区块。这提供了块之间的良好分离,并允许您保证相关字段具有相同的数字标记,但它确实使处理复杂化。
The alternative is to append incrementing numbers to each field name, as you duplicate the existing field sets for each new block. This provides a nice separation between blocks and allows you guarantee that related fields have the same numerical tag, but it does complicate processing.
这篇关于添加多个输入到文件php表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!