CActiveForm errorSummary mixed models


In my form I display fields from two models User and Role.

The problem is that although the Role is a required attribute in Role model it doesn’t appear in the error summary box.

this is my code:

<?php echo $form->errorSummary(array($model,$role)); ?>

where $model refer to main model(User) and $role to Role model




                   <?php echo $form->labelEx($role,'Ruolo'); ?>





                    <?php echo $form->dropDownList($role,'Ruolo',CHtml::listData($role->GetMainRoles(),"IDRole","Ruolo"),array('prompt'=>'Seleziona')); ?>

                    <?php echo $form->error($role,'Ruolo'); ?>



the label is marked as required but if I dont select any role and submit the role info is not added to errorSummary text.

How do you call the validation in the controller?

I left the following row commented:

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

so not Ajax validation.

That’s OK but you are using two models… so you need to validate them both…

may you please show me how to do that?

Check this wiki article -How to use a single form to collect data for two or more models?

Ok. thank you it was helpfull.