我有一个更改密码的操作。我不明白为什么 $error 为空;
public function actionChangePassword() {
$error;
$player = $this->loadModel(Yii::app()->user->id);
$oldpassword = '';
$newpassword = '';
$newpasswordrepeat = '';
if (!isset($_REQUEST['oldpassword']) || !isset($_REQUEST['newpassword']) || !isset($_REQUEST['newpasswordrepeat'])) {
$error = 'Vui long dien day du';
}
if (isset($_REQUEST['newpassword']) && isset($_REQUEST['newpasswordrepeat']) && isset($_REQUEST['oldpassword'])) {
$oldpassword = $_REQUEST['newpassword'];
$newpassword = $_REQUEST['newpassword'];
$newpasswordrepeat = $_REQUEST['newpasswordrepeat'];
if ($player->password != EncryptManager::encryptPassword($_REQUEST['oldpassword'])) {
$error = 'Password cu khong dung';
if ($newpasswordrepeat != $newpassword) {
$error = 'Lap lai password khong dung';
}
if (count($newpassword))
$error = 'Nhap password phai tren 6 ky tu';
if (!isset($error)) {
$player->password = EncryptManager::encryptPassword($_REQUEST['newpassword']);
echo 'new password';
if ($player->save()) {
$this->redirect(Yii::app()->baseUrl);
}
}
}
}
$this->render('//site/changepassword'
, array('error' => $error)
);
}
和我的看法更改密码
<div class="change-password-layout">
<div class="change-password-content" >
<?php echo CHtml::beginForm(); ?>
<div class="change-password-detail-total">
<div class="change-password-title"><p>Đổi mật khẩu</p></div>
<div class="change-password-detail">
<p>Mật khẩu cũ </p>
<input type="password" name="oldpassword" value="">
</div>
<div class="change-password-detail">
<p>Mật khẩu mới </p>
<input type="password" name="newpassword" value="">
</div>
<div class="change-password-detail">
<p>Xác nhận lại mật khẩu mới </p>
<input type="password" name="newpasswordrepeat" value="">
</div>
<div class="submit-button">
<input type="submit" name="" value="Xác nhận">
<input type="button" name="" value="Hủy bỏ" />
<div class="clearboth"></div>
</div>
</div>
<?php echo $error; ?>
<?php echo CHtml::endForm(); ?>
</div>
<div class="change-password-bg-total">
<div class="change-password-bg"></div>
</div>
<?php if ($error != '') { ?>
<div class="msg-error">
<div class="signup-line"></div>
<div class="msg-item">
<div class="msg-warning-icon"></div>
<div class="msg-warning-label">
<?php echo $error; ?>
</div>
<div class="clearboth"></div>
</div>
<div style="height:5px"></div>
<div class="signup-line"></div>
</div>
<?php } ?>
</div>
<script>
$("#set-height").css('height',$(window).height());
</script>
当用户没有填写完整的字段时,如果成功重定向到主页,我们会收到错误消息。感谢提前!