PHP:当多个表单字段共享相同的名称时使用 postID [英] PHP: using post when mutliple form fields share same name & id

查看:26
本文介绍了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.

这篇关于PHP:当多个表单字段共享相同的名称时使用 postID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆