I think a simple way would be to validate using javascript. You could do some ajax or something when the field loses focus and send a message above it, if it fails.
But other then that i'm not sure i haven't tried anything of that sort. On May 29, 1:32 pm, jgadbois <[email protected]> wrote: > 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 <[email protected]> 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 <[email protected]> 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
