Revision #4                                    has been created by 
 jonah                                    on Mar 25, 2009, 11:55:20 PM with the memo:
                                
                                
                                    improved code formatting                                
                                                                    « previous (#3)                                                                                                    next (#5) »                                                            
                            Changes
                            
    Title
    unchanged
    Using CAutoComplete to display one value and submit another
    Category
    unchanged
    Tutorials
    Yii version
    unchanged
    
    Tags
    unchanged
    
    Content
    changed
    [...]
In your controller, create a new action to handle autocomplete lookup queries, like so:
```php
<?php
    //...Action
    public function actionAutoCompleteLookup()
    {
       if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))
       {
			
    //
* q is the default 
varGET variable name that is used by
 
					// the autocomplete widget to pass in user input
			*/
 
          $name 
               = $_GET['q']; 
					// this was set with the "max" attribute of the CAutoComplete widget
          $limit 
              = $_GET['limit']; 
          $criteria 
           = new CDbCriteria;
          $criteria->condition = "name LIKE :sterm";
          $criteria->params 
   = array(":sterm"=>"%$name%");
          $criteria->limit 
    = $limit;
          $userArray 
          = User::model()->findAll($criteria);
          $returnVal 
          = '';
          foreach($userArray as $userAccount)
          {[...]
die();
    }
    //...
 
    ?>
 
```
There are a few things to notice here:
<ol>
<li>A pipe "|" delimiter is used and natively recognized by jQuery to split a returned item into parts</li>
<li>Each autocomplete item is terminated by a newline character, or "\n"; note that the newline char must be enclosed in double quotes (") not single quotes(')</li>[...]