Ajax validation and flash


I have a problem with the flash message when I validate my login form by ajax.

I noticed that when I type the username and password, and being in the password I click login the message don’t show. However, when in the first I click on the background of the page (leave password box) and then click the login button the message will show.

My code:


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(

	'action' => array('user/login'),




)); ?>

	<div class="row">

    	<?php echo $form->labelEx($model,'username'); ?>

    	<?php echo $form->error($model,'username'); ?>

    	<?php echo $form->textField($model,'username'); ?>


	<div class="row">

    	<?php echo $form->labelEx($model,'password'); ?>

    	<?php echo $form->error($model,'password'); ?>

    	<?php echo $form->passwordField($model,'password'); ?>


	<div class="row rememberMe">

    	<?php echo $form->checkBox($model,'rememberMe'); ?>

    	<?php echo $form->label($model,'rememberMe'); ?>


	<div class="row buttons">

    	<?php echo CHtml::submitButton('Login'); ?>


<?php $this->endWidget(); ?>

</div><!-- form -->

Login action:


     * Login user


	public function actionLogin()


		$model=new LoginForm;

		// if it is ajax validation request

		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')


			echo CActiveForm::validate($model);



		// collect user input data




			// validate user input and redirect to the previous page if valid

			if($model->validate() && $model->login()) {






Anyone ever had a similar problem?

Thanks for help.

:) I found solution. Maybe someone need it. The problem disappears when is set validationDelay=0.

Best regards.

I’ve also had the same problem and have found another solution:

You have to set $autoUpdateFlash = false in your CWebUser object or in it’s child class.

From now flash messages will be available until you retrieve them with getFlash($key) or getFlashes().