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

查看:53
本文介绍了PHP:当多个表单字段共享相同的名称时使用帖子&ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该标题可能意义不大,但是我所拥有的是一种动态生成的表格.我挂在一张产品表上,拿出那里的名字.然后,我创建一个显示该产品的表单,该表单旁边有一个复选框和一个文本框.

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?

干杯

Jonesy

推荐答案

使用 name ="chk []" ,PHP将为您创建一个数组.

Use name="chk[]", then PHP will create an array for you.

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

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