以下是我所拥有的: 输入类型文本框是从数据库中动态呈现的。代码如下:
{foreach from = $folderslist item=List}
<input type="text" name="{$List.widgetid}" id="wcolor" value="{$List.color}" maxlength="6" onChange="display_screenplay_color('fcolor_id',this.value)" style="width:48px;">
<span style="color:#{$List.color}">{$List.items} </span>
{/foreach}
该列为widgetid
。
所以对于每个widgetid,我们想要一个id="$idfromdb"
字段名称和旁边的文本框
这样,在您点击SUBMIT后,它会发布所有数据。我想要一个循环,它将使用文本框的值更新数据库。我想知道我是否可以循环$_POST
但是使用正则表达式,因为所有小部件ID都以“w”开头,或者我可以获得每个文本框的提交值$_POST
,它们的ID以“w”开头”。或任何其他想法/建议?
答案 0 :(得分:1)
您可以使用name[]
或name[id]
作为输入的名称,PHP会将此转换为关联数组。
<form action="test.php" method="post">
<input type="text" name="widget[5]" id="widget_5" value="5" />
<input type="text" name="widget[6]" id="widget_6" value="6" />
<input type="text" name="widget[9]" id="widget_9" value="9" />
<input type="submit" />
</form>
$ _ POST将包含此信息
array
'widget' =>
array
5 => string '5' (length=1)
6 => string '6' (length=1)
9 => string '9' (length=1)
你现在可以用
循环foreach ($_POST["widget"] as $widgetId => $value)
[...]