Ajax validation and flash

Hi,

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:

LoginFormPortletView.php




<div class="form">

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

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

	'id'=>'login-form',

	'enableAjaxValidation'=>true,

	),

)); ?>

	<div class="row">

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

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

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

	</div>


	<div class="row">

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

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

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

	</div>


	<div class="row rememberMe">

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

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

	</div>


	<div class="row buttons">

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

	</div>


<?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);

			Yii::app()->end();

		}


		// collect user input data

		if(isset($_POST['LoginForm']))

		{

			$model->attributes=$_POST['LoginForm'];

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

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

            	Yii::app()->user->setFlash('success-login',"Login");

				$this->redirect(Yii::app()->user->returnUrl);

        	}

		}

	}




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().