CActiveForm ajax验证错误未显示在表单中

CActiveForm ajax验证错误未显示在表单中,ajax,yii,Ajax,Yii,我在yii中使用CActiveForm创建了一个表单。我正在使用ajax使用CHtml::ajaxSubmitButton提交表单。使用ajax提交表单工作正常,我能够使用$\u POST['modelname']['fieldname']获取控件中的值。但是ajax表单验证工作不正常。下面是代码 <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'item-brand-form',

我在yii中使用CActiveForm创建了一个表单。我正在使用ajax使用CHtml::ajaxSubmitButton提交表单。使用ajax提交表单工作正常,我能够使用$\u POST['modelname']['fieldname']获取控件中的值。但是ajax表单验证工作不正常。下面是代码

<?php 
    $form=$this->beginWidget('CActiveForm', array(
    'id'=>'item-brand-form',
    'enableAjaxValidation' => true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
     ),
    'htmlOptions'=>array(
        'class'=>'form-horizontal',
    ),
)); ?>

<div class="form-group">
<?php echo $form->labelEx($model,'Brand Name',array('class'=>'control-label col-lg-4','for'=>'ItemBrand_brand_name')); ?>
<div class="col-lg-6">  
<?php echo $form->textField($model,'brand_name',array('class'=>'form-control')); ?>  
<?php echo $form->error($model,'brand_name'); ?>            
</div>
<!-- End col-lg-6 -->
</div><!-- End Form Group -->


<div class="form-group">
<?php echo $form->labelEx($model,'Brand Code',array('class'=>'control-label col-lg-4','for'=>'ItemBrand_brand_code')); ?>
<div class="col-lg-6">                  
<?php echo $form->textField($model,'brand_code',array('class'=>'form-control')); ?> 
</div>
<!-- End col-lg-6 -->
</div><!-- End Form Group -->


<div class="form-group">
<div class="col-lg-4"></div>
<div class="col-lg-2">
<?php echo CHtml::ajaxSubmitButton('Apply',array('class'=>'btn btn-lg btn-primary')); ?>
</div>
</div>
<?php $this->endWidget(); ?>
所以我用的是

if(Yii::app()->getRequest()->getIsAjaxRequest()) 
        {
        echo CActiveForm::validate( array( $model)); 
        Yii::app()->end(); 
        }
在浏览器中检查时,我得到了响应

{"ItemBrand_brand_name":["Brand Name cannot be blank."]}
但表单中未显示错误消息。还有为什么$u POST['ajax']不起作用?请帮忙。
提前感谢。

我已经通过使用CHtml::submitButton而不是CHtml::ajaxSubmitButton解决了这个问题,然后在表单“afterValidate”选项中使用jQuery$.ajax函数提交表单。请查看表单中的详细信息。@kumar_v我尝试过使用它,但它不起作用。尝试客户端验证truewith'enableClientValidation'=>true,当焦点超出“brand_name”字段时,它显示错误。提交表单时没有显示错误。您好,您找到解决方案了吗?
{"ItemBrand_brand_name":["Brand Name cannot be blank."]}