如果我长篇小说,我有一个简短的表格(输入,选择和三个复选框)。我在一个按钮上创建了一个函数,可以在我的页面上动态添加这个表单的多个实例。它将它保存为数组(即输入名称为name =“checkbox []”),这将在我的数据库中保存。我遇到的问题是我可能有6个这种形式的实例,但只检查了一些框。所以,我可能有6个文本输入,6个选择输入,但可能只有3个复选框输入。由于它只有3个输入,因此数组只有3个数据,当我运行for()语句时,它不能准确地保存这些信息并将其绑定到正确的记录。
我想也许我可以有一个隐藏的输入,它将通过javascript分配它的值,但我不知道如何适当地引用复选框(你不能做id =“blahblah []”对吗?)
悲伤和困惑,
ImmortalFirefly
答案 0 :(得分:1)
我不确定我是否抓住了你的漂移,但请考虑一下:
<?php
var_dump( $_POST )
?>
<form name=form0 method= post action = "">
<input type=checkbox name=checkbox[0][0] />
<input type=checkbox name=checkbox[0][1] />
<input type=checkbox name=checkbox[0][2] />
<input type = submit>
</form>
Then another form is added
<form name=form1 method= post action = "">
<input type=checkbox name=checkbox[1][0] />
<input type=checkbox name=checkbox[1][1] />
<input type=checkbox name=checkbox[1][2] />
<input type = submit>
</form>
在html中将其模拟并将其发布回网页并查看其工作原理,您可以遍历帖子值以查看发送的表单和检查的框,或者将其全部放在一个表单中。
<?php
var_dump( $_POST )
?>
<form name=form0 method= post action = "">
<input type=checkbox name=checkbox[0][0] />
<input type=checkbox name=checkbox[0][1] />
<input type=checkbox name=checkbox[0][2] />
<input type = submit>
Then another series of checkboxes is added :
<input type=checkbox name=checkbox[1][0] />
<input type=checkbox name=checkbox[1][1] />
<input type=checkbox name=checkbox[1][2] />
close off the form
<input type = submit>
</form>