name availability in yii

Hi everybody, I getting a problem to check username availability checking using jquery.

this is my form page…

<?php

Yii::app()-&gt;clientScript-&gt;registerCoreScript('jquery');


Yii::app()-&gt;clientScript-&gt;registerScriptFile(Yii::app()-&gt;request-&gt;baseUrl.'/js/ajaxreq.js');

?>

<div class="form">

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

'id'=&gt;'mst-thana-form',


'enableAjaxValidation'=&gt;false,

)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;


&lt;p class=&quot;note&quot;&gt;&amp;nbsp;&lt;span id=&quot;msgbox&quot; style=&quot;display:none&quot;&gt;&lt;/span&gt;&lt;/p&gt;


&lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;


&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'name'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'name',array('size'=&gt;50,'maxlength'=&gt;50,'id'=&gt;'name', 'link'=&gt;Yii::app()-&gt;request-&gt;baseUrl.'/protected/availability.php', 'onKeyup'=&gt;'isDoubleByte(event,this.id)')); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'name'); ?&gt;


&lt;/div&gt;


&lt;div class=&quot;row buttons&quot; style=&quot;display:none&quot; id=&quot;butt&quot;&gt;


	&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;


&lt;/div&gt;

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

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

This is my ajaxreq.js file…

$(document).ready(function()

{

&#036;(&quot;#name&quot;).blur(function()


{


	&#036;(&quot;#msgbox&quot;).removeClass().addClass('messagebox').text('Checking...').fadeIn(&quot;slow&quot;);


	&#036;.post(&quot;protected/availability.php&quot;,{ user_name:&#036;(this).val()} ,function(data)


    {


	  if(data=='no') //if username not avaiable


	  {


	  	&#036;(&quot;#msgbox&quot;).fadeTo(200,0.1,function() 


		{ 


		  &#036;(this).html('This name Already exists').addClass('messageboxerror').fadeTo(900,1);


		});		


      }


	  else


	  {


	  	&#036;(&quot;#msgbox&quot;).fadeTo(200,0.1,function()  


		{ 


		  &#036;(this).html('name available to create').addClass('messageboxok').fadeTo(900,1);	


		});


		&#036;('#butt').show();


	  }				


    });





});

});

and this is availability.php file…

<?php

$rowId = 0;

$user_name=$_POST[‘user_name’];

$district=$_POST[‘district’];

$fa = MstUser::model()->findAllByAttributes(array(‘name’=>$user_name));

		&#036;ld=CHtml::listData(&#036;fa,'userId','userId');


		foreach(&#036;ld as &#036;i){


			&#036;rowId = &#036;i;


		}

if ($rowId!=0)

{

echo $rowId;

}

else

{

echo $rowId;

}

?>

when I check user availability it still showing "checking…"

please any one help me.

Too much code … wont read it … post the essential parts only

check firebug to see what is the response of the ajax request

thanks Gustavo,

in my js file I am trying to check available user name.

which is check in availability.php file and it is call from js file.

is this code is correct??

$.post("protected/availability.php",{ user_name:$(this).val()} ,function(data)

thanks again.

Hey

Yea, it is correct … then get $_POST[‘user_name’]

but like I said, the best thing to do is to check the ajax request in firebug

working on a saturday ?

In case you’re fine with ajax validation in whole form (i don’t think it can be enabled/disabled) in parts of it, you can enableAjaxValidation and create a unique validation rule in username.

I think it’s more clear this way…