Yii - Using Ajax Validation

2019-03-27 05:52发布

I'm trying to enable ajax validation in a form, I've added the right parameters to the form, but it's not working, here's my code:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'user-form',
    'enableAjaxValidation'=>true,
    'htmlOptions' => array(
            'enctype' => 'multipart/form-data',
            'enableClientValidation'=>true
    ),
)); ?>

Please advice.

标签: ajax yii
1条回答
姐就是有狂的资本
2楼-- · 2019-03-27 06:13

In the top of your action, add the following lines:

if(isset($_POST['ajax']) && $_POST['ajax']==='user-form'){
    echo CActiveForm::validate($model);
    Yii::app()->end();
}
查看更多
登录 后发表回答