Ajax request

Hello. I have a input tab.

 <?php echo CHtml::textField('name', '', array('id'=>'playerName'));?>

I want to show autoComplete list of players’ names by ajax request when user start typing on the input tab like google.

Help me to this please.

Dear Dijgee,

Just replace the following

 <?php echo CHtml::textField('name', '', array('id'=>'playerName'));?>


<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(


      'source'=>array('name1','name2','name3'....),//or Define a method to get the data from database


          'minLength'=>'2' ),

  )); ?>

Once you submit the form, you can get the selected name from $_POST[‘name’].


Thank you.

What if i like to user CActiveRecord array as a source?


You can get an array of datas from CActiveRecord like below


$C = new CDbCriteria;

$C->select = "title";

$data = CActiveRecord::model()->findAll($C);


Or if more complicated you can use ajax calls to get datas (and then do whatever you need to) with parameters sourceUrl