Thanks that helps a lot...I got it working. Now I have another
problem :)  I would like the user to add as many ingredients as he/she
wants.  Basically I have a link ("Add another ingredient") that
executes javascript and adds the new form fields.  This is all working
fine and saving to the db via saveAll().  However, if for some reason
validation fails, I lose the form fields added via javascript.  Is
there any way to get around this?  In other words I think somehow the
controller needs to detect the count of submitted ingredients and pass
that back to the view.  Any ideas on how to do this?

On May 29, 11:22 am, Ithaka <justin_d1...@hotmail.com> wrote:
> Pretty simple Jgadbois,
>
> Here could be a little example of what u would want. (in cakephp 1.2)
>
> //this doesn't have to be so complicated but im just showing u the
> options of the create
> //function. create('Recipe'); would automagically bring you to the add
> action.
> echo $form->create('Recipe', array('method' => 'post', 'url' => array
> ('action' => 'add')));
>   echo $form->input('Recipe.name');
>   echo $form->input('Ingredients.name');
>   echo $form->input('Ingredients.quantity');
> echo $form->end();
>
> That is the code within the view, in the controller you can do all the
> logic you want with this stuff by looking at $this->data.
> $this->data would look something like this:
> array (
>        [Recipe] => array (
>                                   [name] => hot fudge cake
>                                  )
>        [Ingredients] => array (
>                                        [name] => flower
>                                        [quantity] => 2
>                                        )
> )
>
> and to save this information all you need to do is use the saveAll
> function
> $this->Recipe->saveAll($this->data);
>
> the saveAll method looks for associations and saves the information
> properly.
>
> I hope this helped you, i'm not sure how new you are so i tried to put
> it as simple as possible and explain things.
>
> Happy Baking.
>
> On May 29, 10:44 am, jgadbois <jgadb...@gmail.com> wrote:
>
> > What is the preferred way for handling a form with elements for
> > mutitple models?  In my case, I'd like to have a form where you can
> > add a Recipe with all of it's Ingredients (a recipe hasMany
> > ingredients).  How would I handle this?  I'm new to CakePHP so I'm a
> > little confused.

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to