Имею форму авторизации, на которой включен enableAjaxValidation. Также включены clientOptions: validateOnSubmit => true, validateOnChange => false. Но не срабатывает.
Привожу исходники:
Контроллер: SiteController
function actionLogin() {
if (Yii::app()->user->isGuest) {
$model = new LoginForm;
if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
echo CActiveForm::validate($model);
Yii::app()->end;
}
if (isset($_POST['LoginForm'])) {
$model->attributes = $_POST['LoginForm'];
if ($model->validate() && $model->login()) {
$this->redirect(Yii::app()->user->returnUrl);
}
}
$this->layout = 'headerFooterOnly';
$this->render('login', array('model' => $model));
} else {
$this->redirect($this->createUrl('site/index'));
}
}
Модель: LoginForm
class LoginForm extends CFormModel {
public $username;
public $password;
public $remember_me;
private $_identity;
public function rules() {
return array(
array('username, password', 'required'),
array('password', 'authenticate'),
);
}
public function authenticate($attribute, $params) {
$this->_identity = new UserIdentity($this->username, $this->password);
if (!$this->_identity->authenticate()) {
$this->addError('password', 'Неверные имя пользователя или пароль');
}
}
public function login() {
if ($this->_identity === null) {
$this->_identity = new UserIdentity($this->username, $this->password);
$this->_identity->authenticate();
}
if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
Yii::app()->user->login($this->_identity);
return true;
} else {
return false;
}
}
}
Представление: login
<div class="column-left">
<h2><?php echo Yii::t('login', 'Авторизация'); ?></h2>
<p id="page-intro"><?php echo Yii::t('login', 'Войдите, чтобы начать работу с TajBay.'); ?></p>
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => 'login-form',
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
),
)); ?>
<div class="content-box">
<div class="content-box-header">
<h3><?php echo Yii::t('login', 'Введите имя пользователя и пароль'); ?></h3>
<div class="clear"></div>
</div>
<div class="content-box-content">
<p>
<?php echo $form->label($model, 'username', array('label' => Yii::t('register', 'Имя пользователя'))); ?>
<?php echo $form->textField($model, 'username', array('class' => 'text-input medium-input')); ?>
</p>
<p>
<?php echo $form->label($model, 'password', array('label' => Yii::t('register', 'Пароль'))); ?>
<?php echo $form->passwordField($model, 'password', array('class' => 'text-input medium-input')); ?>
</p>
<p>
<?php echo $form->checkBox($model, 'remember_me'); ?>
<?php echo $form->label($model, 'remember_me', array('label' => Yii::t('login', 'Запомнить меня'), 'class' => 'checkbox-label')); ?>
</p>
<p>
<?php echo CHtml::submitButton(Yii::t('login', 'Войти'), array('class' => 'button')); ?>
</p>
</div>
</div>
<?php $this->endWidget(); ?>
</div>
<div class="column-right">
<img alt="ad" src="<?php echo Yii::app()->request->baseUrl; ?>/design/images/ad.jpg">
</div>
Ткните новичку пальцем, что не так?