I have a view called Prices.ctp with the following code. It creates a form which echo's all the data from a variable called $products which contains all the data from a table called Products.
<?php echo $this->Form->create('Product', array('action' => 'changePrice')); ?>
<fieldset>
<h3>Products</h3>
<?php
foreach($products as $k=>$v){
echo $this->Form->hidden('id', array('value'=> $v["Product"]['id']));
echo $this->Form->input('name', array('value' => $v["Product"]["name"] ));
echo $this->Form->hidden('slug', array('value'=>$v["Product"]['slug']));
echo $this->Form->hidden('description', array('value'=>$v["Product"]['description']));
echo $this->Form->hidden('cateID', array('value'=>$v["Product"]['cateID']));
echo $this->Form->input('price', array('value' => $v["Product"]['price']));
echo $this->Form->hidden('photo', array('value'=>$v["Product"]['photo']));
echo $this->Form->hidden('photo_dir', array('value'=>$v["Product"]['photo_dir']));
echo $this->Form->hidden('active', array('value'=>$v["Product"]['active']));
echo $this->Form->hidden('views', array('value'=>$v["Product"]['views']));
echo $this->Form->hidden('created', array('value'=>$v["Product"]['created']));
echo $this->Form->hidden('modified', array('value'=>$v["Product"]['modified']));
}?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
It shoots to this controller method, called changePrice
public function changePrice(){
$this->Product->saveMany($this->request->data['Product']);
$this->Session->setFlash( "Prices Saved.");
$this->redirect ( "/admin/products/" );
return;
}
However when I used debug() to check the contents of of $this->request->data it shows that only the final iteration of the foreach loop in the view is being sent.
To re-word, if the original $products variable (passed into the view prices.ctp) has 4 products: product1, product2, product3, and product4, all with their own data from the Product table (id, name, etc), when the submit button is pressed on the page, only product4's variables will be passed into $this->request->data.
Why is this happening?
Cheers