Hmm, this is not quite right either. Now the associated models do not save... According to http://book.cakephp.org/view/85/Saving-Related-Model-Data-HABTM I should be using $form->input('FunctionalArea') but that doesn't work with the validation. But it does work with the save function.
Dave, thanks, I did find that link when Googling for a solution. I was hoping to avoid writing my own validation method since the multiple one does exist, although it doesn't sound like people are having success using it. On Aug 10, 11:49 am, mcrawford <[email protected]> wrote: > Ah, I found it in the Form helper... > > $form->input('Question.FunctionalArea') > > I need to use the full dot-separated name of the field to get the form > field to be what the validation is expecting. > > On Aug 10, 11:32 am, mcrawford <[email protected]> wrote: > > > Hi, > > > I have a model set up like this: > > > class Question extends AppModel { > > var $name = 'Question'; > > var $hasAndBelongsToMany = array( > > 'FunctionalArea' => array('joinTable' => > > 'question_functions') > > ); > > var $validate = array( > > 'title' => 'notEmpty', > > 'content' => 'notEmpty', > > 'FunctionalArea' => array( > > 'rule' => array('multiple', array('min'=>1)), > > 'required' => true > > ) > > ); > > > } > > > Then in my form I set up an input with FunctionalArea as the field > > name, using Cake's form helper. This produces an input with name="data > > [FunctionalArea][FunctionalArea][]". Now if I save the form with NO > > validation, the vanilla $this->Question->save($this->data); works just > > fine. The join table is all correct after saving. > > > But when I put in that validation for FunctionalArea that I have in > > the above code, the validation doesn't work correctly. The model's > > invalidFields method does this: > > if (isset($data[$this->alias])) { > > $data = $data[$this->alias];} > > > So that the data in data[FunctionalArea][FunctionalArea] never gets to > > the validate method. So the validation always fails (because > > FunctionalArea is required). > > > My question is: what is the correct Cake way to do this? I'm trying to > > use the automatic save feature, form fields, and the validation, but I > > don't see how I can use them together, because the validation seems to > > be ignoring the very place where the save needs the data. > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
