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)
{
$search=strtolower($search);
$connection=Yii::app()->db;
$sql ="SELECT `cite` FROM auto_comp WHERE cite LIKE '$search%'";
$command=$connection->createCommand($sql);
$result = $command->query($sql);
if($resultarray = $result->readAll())
{ //convert to array
foreach($resultarray as $keyword2=>$key2)
{
if(strpos(strtolower($key2['city_combo']),$search)!==false)
$results[$keyword2]=$key2['city_combo'];
}
return $results;
}
return array();
}
<?php $this->widget('CAutoComplete', array(
'model'=>$client,
'attribute'=>'name',
'minChars'=>2,
'max'=>100,
'url'=>array('client/search'),
'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;
}
}
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
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?
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
if(isset($_POST[‘ListForm’]))
$list->setAttributes($_POST['ListForm']);</pre> being deleted caused the problem. I can't believe I didn't catch this sooner! <img src='http://www.yiiframework.com/ipb/public/style_emoticons/default/angry.gif' class='bbc_emoticon' alt='>:(' />
Thanks again for your help and patience… much appreciated.