Revision #6 has been created by resurtm on Oct 10, 2011, 11:58:52 AM with the memo:
Proper validation process of multiple models (according to the original article)
« previous (#5) next (#7) »
Changes
Title
unchanged
How to use single form to collect data for two or more models (CActiveForm and Ajax Validation edition)
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
CActiveForm, ajax, several models
Content
changed
[...]
$b=new Info;
$this->performAjaxValidation(array($a,$b));
if(isset($_POST['User'],$_POST['Info']))
{
// populate input data to $a and $b
$a->attributes=$_POST['User'];
$b->attributes=$_POST['Info'];
if($a->save() && $b->save())
// validate BOTH $a and $b
$valid=$a->validate();
$valid=$b->validate() && $valid;
if($valid)
{
// use false parameter to disable validation
$a->save(false);
$b->save(false);
$this->redirect('index');
}
}
$this->render('create',array('a'=>$a,'b'=>$b));
}
protected function performAjaxValidation($models)
{[...]