Difference between #5 and #6 of
How to use single form to collect data for two or more models (CActiveForm and Ajax Validation edition)

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)
{
[...]
15 0
33 followers
Viewed: 59 082 times
Version: 1.1
Category: How-tos
Written by: RusAlex
Last updated by: Darwin Wen
Created on: Jul 20, 2011
Last updated: 6 years ago
Update Article

Revisions

View all history