得到一個字段的參數我在某種形式上有一個foreach
,當我提交時,我得到了控制器中最後一個字段的所有參數。我從表格
形式:
<form action="<?php echo Mage::getUrl('checkout/cart/addmultiple')?>" method="post" id="products_addtocart_form" enctype="multipart/form-data">
<?php foreach ($_productCollection as $prod) : ?>
<div class="border-new-cart-button">
<input type="hidden" name="productId" value="<?php echo $productId ?>" />
<input type="hidden" name="productName" value="<?php echo $prod->getName() ?>" />
<input type="text" class="input-qty-product number-control" title="Qty" value="<?php echo /*$this->getProductDefaultQty() * */ 0 ?>" name="qty" id="qty-<?php echo $productId ?>"/>
</div>
<?php endforeach; ?>
<button class="btn add-to-cart" onclick="this.form.submit()"><span><?php echo $this->__('Validate') ?></span></button>
</form>
控制器:
public function addmultipleAction(){
$params= array($this->getRequest()->getParams());
var_dump($params);
// Result:
Array
(
[0] => Array
(
[productId] => 106
[productName] => shirt
[qty] => 6
[productTagName] =>
)
)
}
編輯:
Now i get them like this:
[productId] => Array
(
[0] => 106
[1] => 107
[2] => 108
[3] => 109
)
[qty] => Array
(
[0] => 4
[1] => 3
[2] => 2
[3] => 1
)
// I want to group the `id` and `qty` per product, something like this:
array(
[0] (
[id] => 106
[qty] => 4
)
[1] (
[id] => 107
[qty] => 3
)
...
)
我不能在表單中找到你的第四個屬性「productTagName」,而它是在你的控制器。 –