I am using yii-user and want to renderpartial a view from the module into another view outside of the module using cjuitabs.
I am able to render the view as expected /view/subscription/index
<? Yii::app()->getModule('user'); ?>
<? $model = new UserChangePassword; ?>
<?php $this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array(
'Subscription'=>$this->renderPartial('/subscription/my', array('model'=>new Subscription), true),
'Account'=>$this->renderPartial('application.modules.user.views.profile.changepassword', array('model'=>$model), true),
),
)); ?>
I wanted to use the logic from /modules/user/controllers/ProfileController actionChangepassword() but could not figure out how.
So I moved the logic to my controllers/SubscriptionController
public function actionIndex()
{
$this->layout = 'subscription-column1';
$this->pageTitle = 'My Subscription';
Yii::app()->getModule('user');
$model = new UserChangePassword;
if(isset($_POST['ajax']) && $_POST['ajax']==='changepassword-form')
{
echo UActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['UserChangePassword'])) {
$model->attributes=$_POST['UserChangePassword'];
if($model->validate()) {
$new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
$new_password->password = Yii::app()->getModule('user')->encrypting($model->password);
$new_password->activkey=Yii::app()->getModule('user')->encrypting(microtime().$model->password);
$new_password->save();
Yii::app()->user->setFlash('profileMessage',UserModule::t("New password saved."));
$this->redirect(array("profile"));
}
}
$this->render('/subscription/index');
}
/code]
My /modules/views/profile/changepassword view
[code]
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'changepassword-form',
'type'=>'horizontal',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->passwordFieldRow($model,'oldPassword'); ?>
</div>
<div class="row">
<?php echo $form->passwordFieldRow($model,'password'); ?>
</div>
<div class="row">
<?php echo $form->passwordFieldRow($model,'verifyPassword'); ?>
</div>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'id' => 'submitBtn',
'buttonType' => 'submit',
'type' => 'primary',
'label' => 'Submit',
'htmlOptions' => array(
'class' => 'btn-primary',
),
));
?>
<?php $this->endWidget(); ?>
I can validate the data, get ajax validation and save. But I do not get error messages from server side validation. Upon the form submitting the view goes back to the first tab. My question is once the changepassword form is submitted how do I do server side validation.
Many thanks.