0

Currently I have two table Products and Orders joined with HABTM. I would like to add the order by ticking product on the list. Below is the code in OrdersController

    $products = $this->Order->Product->find('all');
    $this->set(compact('products'));

Here is the code in orders/add.ctp

<?php 
foreach ($products as $product) 
        { 
            echo "<tr>"; 
            echo "<td class='heading'>".$product['Product']['name']."</td>";
            echo "<td>". $product['Product']['price']."</td>";
            echo "<td class='data'>"; 
            echo $this->Form->input("Product.checkbox.$product", array('label'=>'','legend'=>false,'type'=>'checkbox'));
            echo "</td>"; 
            echo "</tr>"; 
        } 
?>

It display product information and checkbox. When I submit the order, it is not saved into ordersproducts table. Any help would be greatly appreciated.

Patrick
  • 93
  • 1
  • 2
  • 6

1 Answers1

0

put an traling dot i.e '.' like this ,this way it will create checkbox name as array..

echo $this->Form->input("Product.checkbox.$product.",
array('label'=>'','legend'=>false,'type'=>'checkbox'));
Rajeev Ranjan
  • 4,152
  • 3
  • 28
  • 41