Active Record, Fill The Textfield With Autocomplete ?


i want , i choose food’s name with autocomplete and selected food’s name shown in autocomplete and selected food’s calory shown in other textfield and selected food’s id record in my table with activerecord…

i success select food with autocomplete and fill the other textfield food’s calory but i dont record this food id in my table.

i have a table, Yemekler

This table’s fields ; id yemekAdi niteligi kalori

when i click the submit button, i want to selected food’s id record the in my database. But form send food’s name

for record. due to the value not integer, record not success.

Thanks for help.

my codes at below

menu.php view

 <div class="row">

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


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








				        'focus'=>'js:function( event, ui ) {

          						$( "#Menu_yemek1" ).val( ui.item.label );

   								return false;


				   		'select'=>"js:function(event, ui) {



				            	return false;









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


        <div class="row">

                <?php  echo CHtml::textField('kalori1','',array('id'=>'kalori1','disabled' => true)); ?>


KayitController.php controller

public function actionAutocompleteTest() {

	$res =array();

	if (isset($_GET['term'])) {

		$sql = 'SELECT yemekAdi as label, id as value, kalori as kalori1 FROM yemekler ';

		$sql = $sql . ' WHERE  niteligi=1 and yemekAdi LIKE :label'; // Must be at least 1

		$command =Yii::app()->db->createCommand($sql);

		$command->bindValue(":label", '%'.$_GET['term'].'%', PDO::PARAM_STR);

		echo json_encode ( $command->queryAll () );




For some time I’ve been using the EJuiAutocompleteFKField extension that does what you describe, that is displays and searches using a text label but stores and posts an id of selected record.