Friday, January 30, 2009

Display Checkbox Array and read values

Hi,

I am very new to CakePHP (and Google Groups) and now struggle badly
with a Form.

I have got a Site with Main- and Subcategories. In the Form you can
post an entry and choose 1 or more Main and Subcategories.

To keep it easy, I have now started just with the Maincategories. For
this I use checkboxes, which are read out from the database.

foreach($options as $option)
{
echo $form->input('Recipe.maincategory_id.'.$counter.'.',
array(
'label'=>
array(
'text'=>$option
['Maincategory']['maincategory']),
'type' => 'checkbox',
'multiple'=>'checkbox',
'value'=>$option['Maincategory']['id']));
$counter++;

}

This displays my checkboxes nicley. I am now trying to read out the
choosen maincategories and this is where I am badly stuck.

if (!empty($this->data)) {
if ($this->Maincategories_subcategories->saveAll($this->data)) {
$this->Session->setFlash(Entry saved');
}
}

Maincategories_subcategories is my DB Tables to connect
Maincategories, Subcategories and Recipes together.

Can someone tell me if I have set up the checkboxes correctly and tell
me how I than save it aswell? I would think I need a foreach aswell to
go through the Array of the Maincategories, but how would this look? I
am struggling on this issue already a week and just can not get on. I
look forward for any tip which will get me forward on this issue.
Thanks a lot in advance.

Luke

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: