部分ajax验证yii表单


partial ajax validation yii forms

我有以下场景,我在yii上创建了一个表单,并使用javascript和css将表单拆分为多个步骤,所有这些都在一个表单中,但在视觉上被拆分为步骤,现在我已经设置了ajax验证,它运行得很好,问题是,当我单击"下一步"按钮进入表单的下一步时,在进入下一步之前,我想"ajax验证"该特定步骤的字段,以此类推,有什么想法吗?

顺便说一句,我使用的是标准的Yii CActiveForm ajax验证:

            $form = $this->beginWidget('CActiveForm', array(
                'id' => 'formElem',
                'enableAjaxValidation' => true,
                'clientOptions' => array('validateOnSubmit' => true),
                    ));

此扩展可能对您有所帮助。

http://www.yiiframework.com/extension/wizard-behavior/

我最终做了一些javascript函数,根据yii的ajax请求的响应来检查.error类,当我们点击下一个按钮时,我们会按照检查

            $(this).closest("fieldset").each(function(){
                $('input').blur();  //This Will trigger yii's CActiveForm ajax requests and return class .error or .success
            });
            var errchk = $(this).closest('fieldset').find('.error').length;
            /* Here we check for validation before moving to next step*/
            if(errchk){
                alert("Please Complete all Required fields!");
                return false;
            }else{
                void(0); //continue to slide
            }