Here’s my actionCreate:
...
public function actionCreate()
{
$model=new Profiles;
$user = new Users;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Profiles']))
{
$model->attributes=$_POST['Profiles'];
$user->attributes=$_POST['Users'];
$user->username=$model->faculty_id_no;
$user->salt=genRandomString();
$this->tmpPassword = genRandomString();
$user->password=Users::encrypting($model->tmpPassword ,$user->salt);
$user->createtime=time();
$user->lastvisit=time();
$user->email=$model->contact_email;
if($model->validate() && $user->validate()) {
if($user->save()) {
$model->user_id=$user->id;
if($model->save()) {
$this->redirect(array('view','id'=>$model->user_id));
}
}
}
}
$this->render('create',array(
'model'=>$model,
'user'=>$user,
));
}
...
And in my create view file:
...
<div class="row">
<?php echo $form->labelEx($model,'faculty_id_no'); ?>
<?php echo $form->textField($model,'faculty_id_no',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'faculty_id_no'); ?>
<?php echo $form->labelEx($user,'role'); ?>
<?php echo $form->dropDownList($user,'role',Users::showRoles(),array('prompt'=>'< Select a Role >')); ?>
<?php echo $form->error($user,'role'); ?>
</div>
...
This is the picture that happens when I click submit:
1250
, expecting that all the required fields declared will be checked. Apparently, what I expected was incorrect.
So how should I do this? The form should not be saved if the role field, which comes from a different model, is empty.
Thanks for your help in advance.