PHP:当多个表单字段共享相同的名称时使用 postID
这个标题可能没有多大意义,但我拥有的是一个动态生成的表单.我钩进一张产品表,拉出那里的名字.然后我创建了一个表单,显示产品旁边有一个复选框和文本框.
That title probably doesn't mean much but what I have is a form that is generated dynamically. I hooks into a table of products, pulls out there name. I then create a form that displays the product with a checkbox and textbox next to it.
<form id="twitter-feed" name="twitter-feed" action="<?php echo $this->getUrl('tweet/') ?>index/tweet" method="post">
<table><tr>
<?php
$model = Mage::getModel("optimise_twitterfeed/twitterfeed");
$products = $model->getProducts();
foreach ($products as $product){
echo '<tr>';
echo '<td>';
echo '<label for="'. $product .'">' . $product . '</label>';
echo '<br /><input type="text" class="hashtag" name="tags" id="tags" value="#enter, #product, #hastag"';
echo '</td>';
echo '<td><input type="checkbox" name="chk" id="'. $product .'"></td>';
echo '</tr>';
}
?>
<tr><td colspan="2"><input type="submit" name="submit" value="tweet"></td></tr>
</table>
</form>
如您所见,每条记录都有复选框和文本字段.当我检查表单中的 $_POST 数据时,它只保留最后一条记录的字段.
As you can see there are checkboxes and textfields for each record. When I examine the $_POST data from the form it only retains fields for the last record.
有没有办法将所有这些数据传回给动作?
Is there a way to pass all this data back to the action?
干杯,
琼斯
推荐答案
使用name="chk[]"
,PHP会为你创建一个数组.
Use name="chk[]"
, then PHP will create an array for you.
相关文章