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

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

[...]
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true,
)); ?>

<?php echo $form->errorSummary(array($a,$b));

 
 
 ?>

<div class="row">
[...]
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));
}
[...]
Thats all, now you have form with 2 models and ajaxValidation.

 
Links
 
-----
 
- [Chinese version](http://www.itkuaixun.com/bbs/thread-51-1-1.html "Chinese version")
16 0
33 followers
Viewed: 72 488 times
Version: 1.1
Category: How-tos
Written by: RusAlex
Last updated by: Darwin Wen
Created on: Jul 20, 2011
Last updated: 12 years ago
Update Article

Revisions

View all history