I want to use the reset password functionality in Yii. For this, I have 4 fields ie email, currentPassword, newPassword, newPasswordRepeat.
I used the following rules in my model
array('email, currentPassword, newPassword, newPasswordRepeat', 'required'), array('newPasswordRepeat', 'compare', 'compareAttribute'=>'newPassword'), array('currentPassword', 'equalPasswords'),
where equalPasswords is my user-defined rule that checks if the password currentPassword password of my original password.
public function equalPasswords($currentPassword) { $oDbConnection = Yii::app()->db; $oCommand = $oDbConnection->createCommand('SELECT * FROM Superadmin_details where email=:email'); $oCommand->bindParam(':email', Yii::app()->session['email'],PDO::PARAM_STR); $user=$oCDbDataReader = $oCommand->queryRow(); if ($user['password'] != $currentPassword) $this->addError($currentPassword, 'Old password is incorrect.'); }
This rule gives an error on the server side, i.e. when I click the submit button, the page reloads and then an error message appears.
I want to show the error on the client side, as well as other errors.
And I included client side validation in the form.
<?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'contact-form', 'enableClientValidation'=>true, 'clientOptions'=>array( 'validateOnSubmit'=>true, ), )); ?>