Re: Newbie - multiple model instances in one form and validation
Hi! Thanks for the help! Got it resolved. Actually the fault was mine. I was validating the foreign key user_id in both child models UserProfile and UserContact. Thats why the saveAll($this->data, array('validate' => 'only')) or saveAll($this->data, array('validate' => 'first')) was failing. Now removed the validation for user_id in both models and got it work. Currently first validating using saveAll($this->data, array('validate' => 'only')) And then saving as saveAll($this->data, array('validate' => false)) Thanks and regards! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Newbie - multiple model instances in one form and validation
Hi! I haven't used the form helper instead created form using bare html to decrease the server load. The form used can be referred over here http://prowebdesignsolutions.com/refer/ Thanks! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Newbie - multiple model instances in one form and validation
Hi , If the model associations are correct and the for is created using User just user $this->User->saveAll($this->data,array('validation'=>'first')) will validate all the Models, well as I said the model associations must be perfect. Regards Sijo Jose C On Wed, Dec 24, 2008 at 4:25 PM, Nature Lover wrote: > > Hi! > > I am new to CakePHP and currently working on an e-commerce site having > three models: > > User( id, name, joined) > UserProfile( id, user_id, title, age, email ) > UserContacts( id, user_id, name, address) > > Currently receiving data from a form as below: > > $this->data['User']['name'] > $this->data['UserProfile']['title'] > $this->data['UserProfile']['age'] > $this->data['UserProfile']['email'] > $this->data['UserContact']['0']['name'] > $this->data['UserContact']['0']['address'] > $this->data['UserContact']['1']['name'] > $this->data['UserContact']['1']['address'] > > tried to validate data in User controller as: > > $this->User->set($this->data); > $this->User->UserProfile->set($this->data); > $this->User->UserContact->set($this->data); > > if($this->User->validates()) > { >if($this->User->UserProfile->validates()) >{ >if($this->User->UserContact->validates()) >{ >$this->set('status','valid'); >} >} > } > else > {$this->set('status','invalid');} > > Here proper validation fails for UserContacts although showing errors > as > $this->validationErrors['UserContact']['fieldname'] > instead of > $this->validationErrors['UserContact']['0']['fieldname'] and > $this->validationErrors['UserContact']['1']['fieldname'] > > Also tried to use saveAll with validate=only, but failed due to > foreign key constrains as getting error: > > 'This field cannot be left blank' > for > $this->validationErrors['UserProfile']['user_id'] and > $this->validationErrors['UserContact']['0']['user_id'] > $this->validationErrors['UserContact']['1']['user_id'] > > Please help me to get out of this hurdle. > > Thanks! > > > -- Sijo Jose Chakramakkil --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newbie - multiple model instances in one form and validation
Hi! I am new to CakePHP and currently working on an e-commerce site having three models: User( id, name, joined) UserProfile( id, user_id, title, age, email ) UserContacts( id, user_id, name, address) Currently receiving data from a form as below: $this->data['User']['name'] $this->data['UserProfile']['title'] $this->data['UserProfile']['age'] $this->data['UserProfile']['email'] $this->data['UserContact']['0']['name'] $this->data['UserContact']['0']['address'] $this->data['UserContact']['1']['name'] $this->data['UserContact']['1']['address'] tried to validate data in User controller as: $this->User->set($this->data); $this->User->UserProfile->set($this->data); $this->User->UserContact->set($this->data); if($this->User->validates()) { if($this->User->UserProfile->validates()) { if($this->User->UserContact->validates()) { $this->set('status','valid'); } } } else {$this->set('status','invalid');} Here proper validation fails for UserContacts although showing errors as $this->validationErrors['UserContact']['fieldname'] instead of $this->validationErrors['UserContact']['0']['fieldname'] and $this->validationErrors['UserContact']['1']['fieldname'] Also tried to use saveAll with validate=only, but failed due to foreign key constrains as getting error: 'This field cannot be left blank' for $this->validationErrors['UserProfile']['user_id'] and $this->validationErrors['UserContact']['0']['user_id'] $this->validationErrors['UserContact']['1']['user_id'] Please help me to get out of this hurdle. Thanks! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---