Hi
I have a pb when displaying my form in an ajax process
I’m working with yii-user module,
it works fine(= all required fields are required) when in a normal page load
but when called in ajax the form contains 2 models User and Profile
and the User fields required rules are being ignored somehow.
I spend the whole day turning it upside down and couldn’t find the key to the puzzle.
maybe some one has experienced this ?
my controller call :
public function actionCreate()
{
$model=new User;
$profile=new Profile;
if(user()->profile->canCreateMeeting && isset($_POST['User']))
{
$model->attributes = $_POST['User'];
$model->activkey = Yii::app()->controller->module->encrypting(microtime().$model->password);
$model->status = User::STATUS_ACTIVE;//we concider User automatically active
$model->createtime = time();
$model->lastvisit = time();
$profile->attributes = $_POST['Profile'];
$profile->user_id = 0;
if($model->validate() && $profile->validate() ) {
$model->password=Yii::app()->controller->module->encrypting($model->password);
if( $model->save() ) {
$profile->user_id=$model->id;
$profile->save();
echo json_encode(array("result"=>true,"id"=>$model->primaryKey));
exit;
}
} else {
if(Yii::app()->request->isAjaxRequest){
$validate = CMap::mergeArray( $model->getErrors() , $profile->getErrors() );
echo json_encode(array("result"=>false,"errors"=>$validate,'Uerror'=>count($model->getErrors()),'Perror'=>count($profile->getErrors())));
Yii::app()->end();
}
}
}
$this->renderPartial('_formPopin',array(
'model'=>$model,
'profile'=>$profile,
));
}