Enable Rule Multiple Models In One Form

really need help, I have 2 models(pemohon and tanah). I have made these models in one form. but the problem, the rules in both models didn`t work…

Pemohoncontroller.php


public function actionCreate()

{

$modelP=new Pemohon;

$modelT= new Tanah;


// Uncomment the following line if AJAX validation is needed

//$this->performAjaxValidation($modelP);


if(isset($_POST['Pemohon'],$_POST['Tanah']))

{

$modelP->attributes=$_POST['Pemohon'];

$modelT->attributes=$_POST['Tanah'];


$valid=$modelP->validate();

$valid=$modelT->validate() && $valid;

if($valid)

        {

            // use false parameter to disable validation

            $modelP->save(false);

            $modelT->save(false);

            // ...redirect to another page

        }

if(array($modelP->save(),$modelT->save())){

   

$this->redirect(array('view','id'=>$modelP->id));}

}


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

'modelP'=>$modelP,'modelT'=>$modelT

));

}

_form.php


<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(

	'id'=>'pemohon-form',

	'enableAjaxValidation'=>false,

)); ?>


<p class="help-block">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary(array($modelP,$modelT)); ?>


	<?php echo $form->textFieldRow($modelP,'nama',array('class'=>'span5','maxlength'=>20)); ?>


	<?php echo $form->textFieldRow($modelP,'alamat',array('class'=>'span5','maxlength'=>50)); ?>


	<?php echo $form->textFieldRow($modelP,'telp',array('class'=>'span5','maxlength'=>20)); ?>


	<?php echo $form->textFieldRow($modelP,'bertindak_atas',array('class'=>'span5','maxlength'=>45)); ?>


        <?php echo $form->textFieldRow($modelT,'jalan',array('class'=>'span5','maxlength'=>30)); ?>


	<?php echo $form->textFieldRow($modelT,'no',array('class'=>'span5')); ?>


	<?php echo $form->textFieldRow($modelT,'rt',array('class'=>'span5')); ?>


	<?php echo $form->textFieldRow($modelT,'rw',array('class'=>'span5')); ?>


	<?php echo $form->textFieldRow($modelT,'kelurahan',array('class'=>'span5','maxlength'=>30)); ?>


	<?php echo $form->textFieldRow($modelT,'kecamatan',array('class'=>'span5','maxlength'=>30)); ?>


	<?php echo $form->textFieldRow($modelT,'luas_tanah',array('class'=>'span5','maxlength'=>10)); ?>


	<?php echo $form->textFieldRow($modelT,'status_tanah',array('class'=>'span5','maxlength'=>25)); ?>


	<?php echo $form->textFieldRow($modelT,'penggunaan_skrng',array('class'=>'span5','maxlength'=>30)); ?>


	<?php echo $form->textFieldRow($modelT,'fk_pemohon_id',array('class'=>'span5')); ?>




<div class="form-actions">

	<?php $this->widget('bootstrap.widgets.TbButton', array(

			'buttonType'=>'submit',

			'type'=>'primary',

			'label'=>array($modelP->isNewRecord,$modelT->isNewRecord) ? 'Create' : 'Save',

		)); ?>

</div>


<?php $this->endWidget(); ?>



Try to use this:


$valid=$modelP->hasErrors();

Do in this way:

if($modelP->validate() && $modelT->validate()) {

//it’s ok

}