Contents returned from CAutoComplete


I have CAutoComplete working fine, but am having difficult time addressing the content that is returned.  Here is what my form looks like:

<?php $this->widget('CAutoComplete', array(






	'htmlOptions'=>array('size'=>'20'))); ?>	

I also have a button on the form and want to pass the results for CAutoComplete to another page.  I'm doing like so:

<?php echo CHtml::button('Refine',array('submit'=>array('list/list', 'what'=>$list->what))); ?>

It, however, does not pass the contents of $list->what, which should be the contents of the CAutoComplete.  Am I addressing it incorrectly?



What returns 'list/suggest'? can you post that method?

Thanks for you reply PoL.

The list/suggest returns a list of choices from the database, which can be selected.  The one selected should be stored in $list->what?  Or am I missing something?I'm just trying to pass the selection to another page. 

Here is the suggest method if it helps:

protected function getApiSuggestions($search)





	$sql ="SELECT `cite` FROM auto_comp WHERE cite LIKE '$search%'";



	$result = $command->query($sql);



	if($resultarray = $result->readAll())

	{ //convert to array


		foreach($resultarray as $keyword2=>$key2)






		return $results;


	return array();


I have something like this and works perfect:

In my view:

<?php $this->widget('CAutoComplete', array(






	'delay'=>500, //number of milliseconds before lookup occurs

	'matchCase'=>false, //match case when performing a lookup?

	'htmlOptions'=>array('size'=>'40'), //any additional html attributes that go inside of the input field can be defined here

	'methodChain'=>'.result(function(event,item){ location.href="index.php?r=client/show&id="+item[1] })'

	)); ?>

And in my ClientController:

public function actionSearch()


		if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))


			$name                = $_GET['q']; //q is the default var name that is used by the autocomplete widget to pass in user input

			$limit               = $_GET['limit']; //this was set with the "max" attribute of the CAutoComplete widget

			$criteria            = new CDbCriteria;

			$criteria->condition = "name LIKE :name";

			$criteria->params    = array(":name"=>"%".$name."%");

			$criteria->limit     = $limit;

			$clientArray           = Client::model()->findAll($criteria);

			$returnVal           = '';

			foreach($clientArray as $client)


				$returnVal .= $client->name.'|'.$client->id."n";


			echo $returnVal;




Hope this help you… May be you want to see that too:


Thanks Pol, but it doesn't solve the issue.  Let me more clear.

In your example, once the selection is made in the input box, are the contents addressed as $client->name?  In other words, if you want to pass the selection to another page through a button would it look something like

<?php echo CHtml::button('Button',array('submit'=>array('new/page', 'name'=>$client->name))); ?>

This should post with the url looking something like http://yourUrl/index...yourselection.

You need to use jQuery, modifing the 'methodChain' property of CAcutocomplete.

See the doc:http://www.yiiframew…hodChain-detail

What I do is to redirect…

Thanks Pol, I see your point in the example about redirecting. 

That would work if I wanted the selection of the CAutoComplete to redirect to a new page, but I want t a button to generate the redirect.  Reason being that the user will pick a selection from the CAutoComplete plus other selections from dropdownlists.  Then, once complete, they will click the submit button and redirect to a new page. 

This being said, I don't think it would be appropriate to use the methodChain or am I incorrect? 


Then you do not need to pass like this  http://yourUrl/index…=yourselection.

Based on your example

<?php $this->widget('CAutoComplete', array(






	'htmlOptions'=>array('size'=>'20'))); ?>

What yo need es to create the redirec button like this http://yourUrl/index.php?r=new/page

and in the ActionPage of the NewController (again based on the url from the example)


$list->attributes = $_POST['List']; //here $list because is the used in the model of the CAutocomplete.

                              //$_POST['List']; if that is the case…

Hope I can explain myself…

so you can use $list->what;


Finally.  Thanks for your help and patience PoL.  Your last post triggered a thought and sure enough I commented out some code earlier to do some testing and ended up deleting it all together. 

Something as simple as

			$list-&gt;setAttributes($_POST&#91;&#039;ListForm&#039;&#93;);</pre> being deleted caused the problem.&nbsp;  I can&#039;t believe I didn&#039;t catch this sooner! <img src='' class='bbc_emoticon' alt='&gt;:(' />

Thanks again for your help and patience… much appreciated.