title: Yii: Update model values before actionCreate and actionUpdate
body: <p>I have a Location model with the following attributes - </p>
  
  <pre><code>id
  City
  State
  Country
  </code></pre>
  
  <p>I wan't the user to be able to select from a list of existing states / countries, and if an additional item needs to be added it may be typed into a textbox. I've modified the <code>_form.php</code> partial as follows - </p>
  
  <pre><code>// city
  &lt;?php echo $form-&gt;textField($model,'city',array('size'=&gt;60,'maxlength'=&gt;100)); ?&gt;
  
  // state
  &lt;?php echo $form-&gt;dropDownList($model, 'state', CHtml::listData(Location::model()-&gt;findAll(), 'state', 'state')); ?&gt;
  &lt;?php echo CHtml::textField('state2','',array('size'=&gt;60,'maxlength'=&gt;100)); ?&gt;
  
  // country
  &lt;?php echo $form-&gt;dropDownList($model, 'country', CHtml::listData(Location::model()-&gt;findAll(), 'country', 'country')); ?&gt;
  &lt;?php echo CHtml::textField('country2','',array('size'=&gt;60,'maxlength'=&gt;100)); ?&gt;
  </code></pre>
  
  <p><code>state2</code> and <code>country2</code> are not a part of the model attributes. Now, in the Location Controller I have the following action - </p>
  
  <pre><code>public function actionCreate()
  {
      $model=new Location;
  
      // Uncomment the following line if AJAX validation is needed
      // $this-&gt;performAjaxValidation($model);
  
      if(isset($_POST['Location']))
      {
          $model-&gt;attributes=$_POST['Location'];
          if($model-&gt;save())
              $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
      }
  
      $this-&gt;render('create',array(
          'model'=&gt;$model,
      ));
  }
  </code></pre>
  
  <p>I want to set the values like this before this action executes -</p>
  
  <pre><code>if(!empty($_POST['state2'])) $model-&gt;state = $_POST['state2'];
  if(!empty($_POST['country2'])) $model-&gt;country = $_POST['country2'];
  </code></pre>
  
  <p><strong>What I've tried so far</strong></p>
  
  <p><strong>1. Attempt 1</strong>
  I added the lines directly to both <code>actionCreate</code> and <code>actionUpdate</code>. However, I don't think this is a clean solution.</p>
  
  <p><strong>1. Attempt 2</strong>
  I tried adding a filter like this - </p>
  
  <pre><code>public function filterAlternateData($filterChain)
  {
    if(!empty($_POST['state2'])) $_POST['Location[state]'] = $_POST['state2'];
    if(!empty($_POST['country2'])) $_POST['Location[country]'] = $_POST['country2'];
    $filterChain-&gt;run();
  }
  </code></pre>
  
  <p>Then I modified the filters() function like this so that it's bound to the create and update actions - </p>
  
  <pre><code>public function filters()
  {
      return array(
          'accessControl', // perform access control for CRUD operations
          'alternateData + create, update',
      );
  }
  </code></pre>
  
  <p>But this did not work.</p>
  
  <p>Anyone have any ideas?</p>