title: cactiveform error management for client validation
body: <p>I have one applicants count dropdown list in my form. When I choose the number of applicants from dropdown list, i need to enter that much applicants first name, last name etc. And when I click on the submit button I need to show the client validation. How to achieve this.</p>
  
  <p>I created the cactiveform widget.</p>
  
  <p>And my controller will look like</p>
  
  <pre><code>class PolicyFamilyDetailsController extends Controller
  {
   public function actionIndex()
  {
      $PolicyFamilyDetails=new PolicyFamilyDetails;
      $PolicyFamilyApplicant=new PolicyFamilyApplicant;
      $this-&gt;performAjaxValidation($PolicyFamilyDetails);
      if(isset($_POST['continue']))
      {
          print_r($_POST['PolicyFamilyDetails']);
          exit;
  
      }
      Yii::app()-&gt;session['policy_id']=2;
      $data['policy_id']=Yii::app()-&gt;session['policy_id'];
      $data['PolicyFamilyDetails']=$PolicyFamilyDetails;
      $data['PolicyFamilyApplicant']=$PolicyFamilyApplicant;
      $this-&gt;render('index',$data);
  }
  public function actionapplicantList()
  {
      $data=array();
      $PolicyFamilyDetails=new PolicyFamilyDetails;
      $data['PolicyFamilyDetails']=$PolicyFamilyDetails;
      $data['applicant_list']=$_POST['applicant_list'];
      $data['applicant_count']=$_POST['applicant_count'];
      $this-&gt;renderPartial('applicant_list',$data,false,true);
      //$this-&gt;render('applicant_list',$data);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And the model is:</p>
  
  <pre><code>class PolicyFamilyDetails extends CActiveRecord
  {
  public function tableName()
  {
      return 'cis_policy_family_details';
  }
  public function rules()
  {
      // NOTE: you should only define rules for those attributes that
      // will receive user inputs.
      return array(
          array('policy_id, first_name, last_name, dob, gender, height, height_scale, weight, weight_scale, occupation, nationality, passport_no, main_applicant', 'required'),
          );
  }
  }
  </code></pre>
  
  <p>And the views are
   index.php</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function() {
  
  
  
  });
  
  function closeError() {
  hid_remove_count=$('#hid_remove_count').val();
  if ($('input:checked').length==hid_remove_count)
  {
      $('input:checked').each(function(){
          $('#applicant_'+$(this).attr('id')).remove();
      });
      $('#errorBlank_applicant_list').hide();
      $('#errorBox_applicant_list').hide();
  }
  else
      alert('Please choose '+hid_remove_count+' applicant');
  }
  
  &lt;/script&gt;
  
  
  &lt;?php 
  
  $form=$this-&gt;beginWidget('CActiveForm', array(
  'id'=&gt;'policy-registration-form',
  'stateful'=&gt;true,
  'enableAjaxValidation'=&gt;true,
  'enableClientValidation'=&gt;true,
  /*'focus'=&gt;array($model,'startDate'),*/
  'clientOptions'=&gt;array(
      'validateOnSubmit'=&gt;true,
  ),
  )); 
  Yii::app()-&gt;session['form'] = $form;
  //print_r($form);
  ?&gt;
  &lt;div id="innerContainer"&gt;
      &lt;h2&gt;Step 3 - Family Details&lt;/h2&gt;
      &lt;p&gt;Details about you and your family applying for cover:&lt;/p&gt;
       &lt;div id="infoContainer"&gt;
          &lt;div class="item"&gt;
  
          &lt;label class="small" for="noapplicants"&gt;Number of applicants&lt;/label&gt;
  &lt;?php
   $static =   array('1'=&gt;1,'2'=&gt;2,'3'=&gt;3,'4'=&gt;4,'5'=&gt;5,'6'=&gt;6,'7'=&gt;7,'8'=&gt;8,'9'=&gt;9,'10'=&gt;10,);
   $ajax_code = &lt;&lt;&lt;LABEL
   if ($(this).val()=='')
  {
    $('.applicant_list').html('');
    return false;
  }
  var applicant_count=parseInt($(this).val());
  var applicant_list=parseInt($('.applicants').length);
  
  if (applicant_count&lt;=applicant_list)
  {
  //alert(applicant_list);
  applicant_check_list='&lt;p&gt;Please choose any '+(applicant_list-applicant_count)+' applicants that you want to remove.&lt;/p&gt;';
  applicant_check_list+='&lt;input type="hidden" id="hid_remove_count" value="'+(applicant_list-applicant_count)+'"/&gt;';
  for (var i=2; i&lt;=applicant_list; i++)
      applicant_check_list+='&lt;input type="checkbox" id="'+i+'" class="check_list"/&gt;Appilcant '+i+'&lt;br/&gt;';
  $(".applicant_check_list").html(applicant_check_list);
  $("#errorBlank_applicant_list").show();
  $("#errorBox_applicant_list").show();
  return false;
  }
  LABEL;
  
  echo Yii::app()-&gt;session['form']-&gt;dropDownList(
                $PolicyFamilyApplicant,
                'applicants_count',
                $static ,
                array('empty'=&gt;Yii::t('fim','Please Select'),
                'onchange'=&gt;$ajax_code.
                          CHtml::ajax(array(
                            'type'=&gt;'POST',
                              'url'=&gt;$this-&gt;createUrl("policyFamilyDetails/applicantList"),
                            'data'=&gt;array('applicant_count'=&gt;'js:this.value',
                                          'applicant_list'=&gt;'js:$(".applicants").length',
                                             ),  
                            'success'=&gt;'function(data) { $(".applicant_list").append(data) }'
                            )),
  
   ));
   ?&gt;
  
  
         &lt;?php echo $form-&gt;error($PolicyFamilyApplicant,'applicants_count');?&gt;
          &lt;/div&gt;
          &lt;?php $this-&gt;renderPartial('applicant_list',array(
                          'applicant_list'=&gt;0,
                          'applicant_count'=&gt;1,
                          'PolicyFamilyDetails'=&gt;$PolicyFamilyDetails,
                          'form'=&gt;$form,
                          'enableAjaxValidation'=&gt;false
          ));?&gt;
          &lt;div class="applicant_list"&gt;
          &lt;?php //$this-&gt;renderPartial('applicant_list');?&gt;
          &lt;/div&gt;
  
  
  
      &lt;/div&gt;
  
  
      &lt;div id="footer" class="clearfix"&gt;
  
          &lt;div id="fr" class="form-btn-orange"&gt;
          &lt;span&gt; 
          &lt;?php echo CHtml::submitButton('Continue',array('class'=&gt;'btnOrange','name'=&gt;'continue')); ?&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
   &lt;?php $this-&gt;endWidget(); ?&gt;
   &lt;div id="errorBlank_applicant_list"&gt;&lt;/div&gt;
   &lt;div id="errorBox_applicant_list"&gt;
  &lt;img src="&lt;?php echo Yii::app()-&gt;request-&gt;baseUrl;?&gt;/images/infobig.jpg" width="51" height="51" alt="Information" style="float:left;margin: 0 20px 20px 0" /&gt;
  &lt;h2&gt;For your information&lt;/h2&gt;
  &lt;div class="applicant_check_list"&gt;
  &lt;/div&gt;
  &lt;div id="errorOK"&gt;
      &lt;input type="image" value="ok" src="&lt;?php echo Yii::app()-&gt;request-&gt;baseUrl;?&gt;/images/error-ok.gif" onclick="closeError()" /&gt;&lt;/div&gt; 
  &lt;/div&gt;
  </code></pre>
  
  <p>applicant_list.php</p>
  
  <pre><code>&lt;?php //$loop_val=5;
  for ($i=$applicant_list;$i&lt;$applicant_count;$i++) {?&gt;
  
   &lt;div class="clearfix"&gt;
   &lt;div id="applicant_&lt;?php echo $i+1;?&gt;" class="applicants"&gt;
   &lt;h3&gt;&lt;?php echo ($i==0)?'Main Applicant':'Applicant '.($i+1);?&gt;&lt;/h3&gt;
  
  
   &lt;?php
   $value=($i==0)?'Y':'N';
   $cActiveForm=new CActiveForm();
   $form=Yii::app()-&gt;session['form'];
  
   $newCActiveFormObj = new CActiveForm(array(
                                  'enableClientValidation' =&gt;true,
                                  'clientOptions'=&gt;array(
                                                          'validateOnSubmit'=&gt;true,
                                                      ),
                                  ));
  
     echo Yii::app()-&gt;session['form']-&gt;hiddenField($PolicyFamilyDetails,'['.($i+1).']main_applicant',array('value'=&gt;$value));
    echo $form-&gt;hiddenField($PolicyFamilyDetails,'['.($i+1).']policy_id',array('value'=&gt;Yii::app()-&gt;session['policy_id']));
    echo $form-&gt;hiddenField($PolicyFamilyDetails,'applicant_list[]',array('value'=&gt;$i+1));
  
   ?&gt;
   &lt;div class="halfCol float"&gt;
                &lt;div class="item"&gt;
                  &lt;label for="firstname" class="xsmall"&gt;First Name&lt;/label&gt;
                  &lt;?php echo $form-&gt;textField($PolicyFamilyDetails,'['.($i+1).']first_name',array('class'=&gt;'medium'/*,'id'=&gt;'first_name_'.($i+1)*/)); ?&gt;
                  &lt;?php echo $form-&gt;error($PolicyFamilyDetails, 'first_name',array('inputID'=&gt;'PolicyFamilyDetails_'.($i+1).'_first_name'));?&gt;
                  &lt;/div&gt;
  
  
  
              &lt;/div&gt;
  
             &lt;div class="halfCol floatRight"&gt;
                  &lt;div class="item"&gt;
  
                  &lt;label class="xsmall" for="lastname"&gt;Last Name&lt;/label&gt;
                  &lt;?php echo $form-&gt;textField($PolicyFamilyDetails,'['.($i+1).']last_name',array('class'=&gt;'medium')); ?&gt;
                             &lt;?php echo    $form-&gt;error($PolicyFamilyDetails,'last_name',array('inputID'=&gt;'PolicyFamilyDetails_'.($i+1).'_last_name')); ?&gt;&lt;/div&gt;
         &lt;/div&gt;
  
  
          &lt;/div&gt;
  
  
  
  
  
          &lt;/div&gt;
   &lt;?php } ?&gt;   
  </code></pre>