Controller Action
public function actionChangepassword($id)
{
$this->layout = 'formlayout';
$model = new Users;
$model = $this->findModel($id);
$model->scenario = 'changepassword';
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
return $this->render('changepassword', [
'model' => $this->findModel($id),
]);
}
View
<?php use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Users;
/* @var $this yii\web\View */
/* @var $model common\models\Users */
/* @var $form yii\widgets\ActiveForm */
$baseUrl = Yii::$app->request->baseurl;
$baseUrl = str_replace('/admin', '', $baseUrl);
$form = ActiveForm::begin(['enableAjaxValidation'=>true,'validateOnSubmit' => true,'options' => ['enctype'=>'text/hmtl'],'action'=>['/users/changepassword?id='.$model->id]] );
?>
<div class='row'>
<div class="col-md-6">
<div class="row">
<div class="box box-primary">
<div class="box-header">
<div class="box-title">
Change password Information
</div>
</div>
<div class="box-body">
<div class="box-body">
<div class="form-group">
<?= $form->field($model, 'oldpwd')->passwordInput(['maxlength' => true,'placeholder'=>'Enter Old Password', 'value' => '']);?>
</div>
<div class="form-group">
<?= $form->field($model, 'password')->passwordInput(['maxlength' => true,'placeholder'=>'Enter New Password', 'value' => '']);?>
</div>
<div class="form-group">
<?= $form->field($model, 'confirm')->passwordInput(['maxlength' => true,'placeholder'=>'Confirm Password', 'value' => '']) ?>
</div>
<div class="box-footer">
<?= Html::submitButton($model->isNewRecord ? 'Submit' : 'Change Password', ['id'=>'userSubmitBtn','class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<a class="btn btn-danger" href="index">Cancel</a>
</div>
</div><!-- box-body ends -->
</div><!-- box-info ends -->
</div><!-- col-md-6 ends -->
<?php ActiveForm::end(); ?>
</div>
Model:
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
use common\models\Users;
use common\models\Groups;
use common\models\Testdata;
use yii\db\Expression;
use yii\behaviors\BlameableBehavior;
/**
* This is the model class for table "xbox_user".
*
* @property integer $id
* @property string $firstname
* @property string $lastname
* @property string $username
* @property string $email
* @property string $password
* @property string $confirm
* @property string $oldpwd
* @property string $role
* @property string $manage
* @property string $group_user
* @property integer $org_id
* @property integer $created
*
*/
class Users extends \yii\db\ActiveRecord implements IdentityInterface
{
public $confirm;
public $oldpwd;
public static function tableName()
{
return 'user';
}
public function rules()
{
return [
[['confirm','password','oldpwd'],'required','on' => 'changepassword',skipOnEmpty => false]]
];
}
}
The required validation works for confirm, password. but it doesnt work for oldpwd
any suggestions on what the issue could be?