title: php yii send error to form on actionCreate
body: <p>I have the following form which is being used to create new records</p>
  
  <pre><code>&lt;?php
  /* @var $this ComponentsController */
  /* @var $model Components */
  /* @var $form CActiveForm */
  ?&gt;
  
  &lt;div class="form"&gt;
  
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'id'=&gt;'components-form',
      'enableAjaxValidation'=&gt;false,
  )); ?&gt;
  
      &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
      &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'component_id'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'component_id'); ?&gt;
          &lt;?php echo $form-&gt;error($model,'component_id'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;label class="required" for="FixedAsset_original_asset_number"&gt;
              Asset Number
          &lt;/label&gt;
          &lt;input id="Components_original_asset_number" type="text" name="Components[original_asset_number]"&gt;
          &lt;?php //echo Chtml::textField('fixed_asset_id', FixedAsset::model()-&gt;FindByPk($model2-&gt;fixed_asset_id)-&gt;fixed_asset_id); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'description'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'description',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'description'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'manufacturer'); ?&gt;
          &lt;?php //echo $form-&gt;textField($model,'manufacturer'); ?&gt;
          &lt;?php   $manufacturer = Manufacturers::model()-&gt;findAll(array("order"=&gt;"name"));
                  $list = CHtml::listData($manufacturer, 'manufacturer_id', 'name');
                  echo $form-&gt;dropDownList($model,'manufacturer', $list,array()); 
          ?&gt;
          &lt;?php echo $form-&gt;error($model,'manufacturer'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'medium'); ?&gt;
          &lt;?php //echo $form-&gt;textField($model,'medium'); ?&gt;
          &lt;?php   $medium = Medium::model()-&gt;findAll();
                  $list = CHtml::listData($medium, 'medium_id', 'type');
                  echo $form-&gt;dropDownList($model,'medium', $list,array()); 
          ?&gt;
          &lt;?php echo $form-&gt;error($model,'medium'); ?&gt;
  
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'version'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'version',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'version'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'serial_no'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'serial_no',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'serial_no'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'purchase_date'); ?&gt;
          &lt;?php //echo $form-&gt;textField($model,'purchase_date'); ?&gt;
          &lt;?php 
          $this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array(
                  'id'=&gt;'Components_purchase_date',
                  'name'=&gt;'Components[purchase_date]',
                  //'value'=&gt;CTimestamp::formatDate('d/m/Y',$item-&gt;validFrom),
                  // additional javascript options for the date picker plugin
                  'options'=&gt;array(
                          'showAnim'=&gt;'fold',
                          'dateFormat'=&gt;'yy-mm-dd',
  
  
                  ),
                  'htmlOptions'=&gt;array(
                          'style'=&gt;'height:20px;'
                  ),
          ));
  
          ?&gt;
          &lt;?php echo $form-&gt;error($model,'purchase_date'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'disposal_date'); ?&gt;
          &lt;?php //echo $form-&gt;textField($model,'disposal_date'); ?&gt;
          &lt;?php 
          $this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array(
                  'id'=&gt;'Components_disposal_date',
                  'name'=&gt;'Components[disposal_date]',
                  //'value'=&gt;CTimestamp::formatDate('d/m/Y',$item-&gt;validFrom),
                  // additional javascript options for the date picker plugin
                  'options'=&gt;array(
                          'showAnim'=&gt;'fold',
                          'dateFormat'=&gt;'yy-mm-dd',
  
  
                  ),
                  'htmlOptions'=&gt;array(
                          'style'=&gt;'height:20px;'
                  ),
          ));
          ?&gt;
          &lt;?php echo $form-&gt;error($model,'disposal_date'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'model'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'model',array('size'=&gt;60,'maxlength'=&gt;255)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'model'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'nol'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'nol'); ?&gt;
          &lt;?php echo $form-&gt;error($model,'nol'); ?&gt;
      &lt;/div&gt;
  
  
  
      &lt;div class="row buttons"&gt;
          &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;
      &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  
  &lt;/div&gt;&lt;!-- form --&gt;
  </code></pre>
  
  <p>I want to send an error to the field <code>Components_original_asset_number</code> on the form. How would I achieve this. In the controller function I am checking to see if it exists if not I want to display error on form or message. <code>original asset number</code> is part of a separate model which I am displaying on this form.</p>
  
  <pre><code>public function actionCreate()
  {
      $model = new Components;
      $model_fixedAsset = new FixedAsset;
      $model_comAsset = new ComAsset;
  
      // Uncomment the following line if AJAX validation is needed
      // $this-&gt;performAjaxValidation($model);
  
      if(isset($_POST['Components']))
      {
          $model-&gt;attributes=$_POST['Components'];
          $fixedAssetId = null;
  
  
          // Check if asset exist and get PK
          if( $_POST['Components']['original_asset_number'] != "" ){
              //print_r($_POST['Components']);
              $criteria = new CDbCriteria;
              $criteria-&gt;condition = "(original_asset_number = :original_asset_number)";
              $criteria-&gt;params = array(":original_asset_number" =&gt;  $_POST['Components']['original_asset_number'] );
              $fixedAssetRow = FixedAsset::model()-&gt;find($criteria);
              //print_r($fixedAssetRow);
              if($fixedAssetRow){
                  $fixedAssetId = $fixedAssetRow-&gt;fixed_asset_id;
              }
              //echo $fixedAssetId;
          }
  
          if($fixedAssetId){
  
          /*if($model-&gt;save())
              $this-&gt;redirect(array('view','id'=&gt;$model-&gt;component_id));*/
  
          // Create com_asset record
  
          }else{
              //no asset found return error message to input corect asset number or create asset in navision and run php script to update mysql db
          }
      }
  
      $this-&gt;render('create',array(
          'model'=&gt;$model,
          'model_fixedAsset'=&gt;$model_fixedAsset,
          'model_comAsset'=&gt;$model_comAsset,
      ));
  }
  </code></pre>