Perform Ajaxvalidation With 2 Models, One With Multiple Instance

hello,

SomeOne know how to perform ajaxValidation whit 2 models, one has multiple instance.

http://www.yiiframework.com/wiki/362/how-to-use-multiple-instances-of-the-same-model-in-the-same-form/

View:




	<div class="row">

		<?php echo $form->labelEx($model,'tri'); ?>

		<?php echo $form->textField($model,'tri'); ?>

		<?php echo $form->error($model,'tri'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'fk_groupe'); ?>

        <?php echo $form->dropDownList($model,'fk_groupe', CHtml::listData(AdGroupe::model()->findAll(), 'groupe_id', 'description')); ?>

	</div>


 <?php 

  $Langues = baLangue::model()->findAll(array('order'=>'langue_id'));

  $i=-1;

    foreach ($Langues as $Langue) {

      $i +=1;

        ?>

        <div class="row">

            <?php echo $form->labelEx($model,yii::t('view','nom').' ['.$Langue->langue_nom.']'); ?>

            <?php echo $form->textField($modelProfilLangue,'['.$i.']nom'); ?>

            <?php echo $form->error($modelProfilLangue,'['.$i.']nom'); ?>

             

        </div>

        

 <?php

 } 

 ?>



Controller :




public function actionCreate()

	{

		$model=new AdProfil;

        $modelProfilLangue=new AdProfilLangue;


		// Uncomment the following line if AJAX validation is needed

		$this->performAjaxValidation($model,$modelProfilLangue);


        

        if(isset($_POST['AdProfil']))

		{

			$model->attributes=$_POST['AdProfil'];

                                 

            $transaction=$model->dbConnection->beginTransaction();

            // pour avoir les langues dans le meme ordre que sur la form

            $Langues = baLangue::model()->findAll(array('order'=>'langue_id'));

            try

            {

               $model->profil_id = AdDroit::getNewId("Ad_profil", 'profil_id');

               $model->save();

                                        

               $i =-1;

               

               foreach($_POST['AdProfilLangue'] as $postAdProfilLangue) 

               {                  

                   $i +=1;                   

                   $modelProfilLangue=new AdProfilLangue;

                   //$modelProfilLangue->performAjaxValidation($modelProfilLangue);

                   $modelProfilLangue->attributes = $postAdProfilLangue; 

                   $modelProfilLangue->fk_langue = $Langues[$i]->langue_id;

                   $modelProfilLangue->fk_profil = $model->profil_id;

                   $modelProfilLangue->save();

               }

                $transaction->commit();

                Yii::app()->user->setFlash('messageToDisplay', yii::t('messsages','L\'enregistrement a été effectué!'.$str));

				$this->redirect(array('admin'));

            }

            catch (Exception $e)

            {

                $transaction->rollback();

                //Yii::app()->user->setFlash('messageToDisplay',yii::t('messsages','Probleme update!'));	

                Yii::app()->user->setFlash('messageToDisplay',$e->getMessage());

            }

            

		}

        


		$this->render('create',array(

			'model'=>$model,

            'modelProfilLangue' => $modelProfilLangue,

		));

	}



Thank you

Nath

at this point, I have a error message :

But I still can not have the message in my view.





    protected function performAjaxValidation2($modelProfil, $attributes=null, $loadInput=true)

    {

       

        if(isset($_POST['ajax']) && $_POST['ajax']==='ad-profil-form')

        {

             $result=array();

            if($loadInput && isset($_POST[get_class($modelProfil)]))

				$modelProfil->attributes=$_POST[get_class($modelProfil)];  

            $models=array($modelProfil);

        

            if (isset($_POST['AdProfilLangue']))

            {

                foreach($_POST['AdProfilLangue'] as $postAdProfilLangue) 

               {  

                    $modelProfilLangue=new AdProfillangue;

                    $modelProfilLangue->attributes=$postAdProfilLangue;

                    array_push($models,$modelProfilLangue);    

               }               

            }

        

            foreach($models as $model)

            {

                $model->validate($attributes);

                foreach($model->getErrors() as $attribute=>$errors)

                    $result[CHtml::activeId($model,$attribute)]=$errors;

            }    

            echo '<pre>';

            print_r($result[CHtml::activeId($model,$attribute)]);

            echo '</pre>';

            

            return function_exists('json_encode') ? json_encode($result) : CJSON::encode($result);         

        }

     }

    

   protected function performAjaxValidation($modelProfil, $attributes=null, $loadInput=true)

  {

       

        if(isset($_POST['ajax']) && $_POST['ajax']==='ad-profil-form')

        {

            echo $this->performAjaxValidation2($modelProfil);

			Yii::app()->end();

        }

   }



any ideas to help me ?