Monday, 15 April 2013

Ajax Based Yii Login Validation

Below is the one change for how to make Ajax Based YII Login validation.

Here we are assuming you have installed and configured YII and is running.

Go to project_name/protected/views/site/login.php and make the below changes


<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>



by default the property of CActiveForm for validation is enableClientValidation, So we have to change it to enableAjaxValidation, So the code would be looking like this 


<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableAjaxValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>


And try login by putting invalid login credentials.

You can test by placing a time below password div , So you can see if you are putting invalid credential and submit by hitting Login button it will show  Incorrect username or password and the time will not be changing.

Below is the code which you have to place for testing under password div
<p>
<?php print date("M, d  Y  H:i:s")?>
</p>

More over you can make the  'validateOnSubmit'=>true,  to  'validateOnSubmit'=>false,   So you see the validation   onBlur.



2 comments:

  1. It will show you errors for invalid credentials but will not authenticate you.

    Here is solution: http://tahiryasin.wordpress.com/2013/05/23/ajax-based-yii-login-form/

    ReplyDelete