我有登录的新主页并使用未登录用户注册。主页.php
<script type="text/javascript" >
$(document).ready(function()
{
$("#btnLogin").click(function()
{
var username= $("#usernamelogin").val();
var password=$("#passwordlogin").val();
var remember = $("#rememberlogin").is(':checked');
var dataString = 'usernamelogin='+ username + '&passwordlogin=' + password + '&rememberlogin=' + remember;
$.ajax
({
type: "POST",
url: "homepage",
data: dataString,
cache: false,
success: function(html)
{
alert(html);
}
});
});
});
</script>
<form action="" method="post" name="frmLogin" class="Login">
<table width="960px" align="center">
<tr>
<td rowspan="3" width="404"><label id="lbbanner"><b>UIT SOCIAL NETWORK</b></label></td>
<td width="216"><label>Username:</label></td>
<td width="324">Password:</td>
</tr>
<tr>
<td><input type="text" witdth="200px" id ="usernamelogin" name="txtUsernameLogin" /></td>
<td><input type="password" width="200px" id="passwordlogin" name="txtPasswordLogin" /></td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" id="rememberlogin" name="checkRemember" /> Remember me!
<input type="button" value="Log in" id="btnLogin" name="Login"/></td>
<td colspan="2" align="right"></td>
</tr>
<tr>
</tr>
</table>
</form>
在 SiteController 我有 actionHomePage()
public function actionHomePage() {
$model = new LoginForm();
$model->username = $_POST['usernamelogin'];
$model->password = $_POST['passwordlogin'];
$model->rememberMe = $_POST['rememberlogin'];
//echo $model->errors;
print_rcount(($model->getErrors()));
//echo $model->username . "&&" . $model->password . "$$" .$model->rememberMe;
// validate user input and redirect to the previous page if valid
if ($model->validate() && $model->login()) {
$this->loginStatus = true;
//$this->redirect(Yii::app()->user->returnUrl);
echo "SUCCESS";
} else {
echo "Error";
}
}
当我用正确的信息填写用户名和密码但它返回“错误”时,$model->validate() 是错误的,但我有正确的信息。我不知道我在这部分有什么问题。