在弹出框中提交错误? [英] Errors on submit in a popup box?

查看:28
本文介绍了在弹出框中提交错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在弹出对话框中显示表单中的验证错误?我想在弹出对话框中显示这些错误,而不是将其作为单独的 div 显示在表单顶部,以便用户单击确定并关闭框.如何在 yii 中执行此操作?

How to show the validation errors in a form in a pop dialogue box?Instead of showing it in the top of the form as a separate div, i want to show those errors in a popup dialogue box so that user clicks okay and dismiss the box.How to do this in yii?

推荐答案

将自己的javascript函数名注册到afterValidate,这是clientOptions属性中的选项之一在 CActiveForm 表单类中.

Register your own javascript function name to the afterValidate, which is one of the options in clientOptions property in CActiveForm form class.

你的表单声明应该有

     'clientOptions' => array(
            'validateOnSubmit' => true,
            'afterValidate' => 'js:myFunc',
     ),

您的表单将如下所示

                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id' => 'a-form',
                    'enableClientValidation' => true,
                    'enableAjaxValidation' => true,
                    'errorMessageCssClass' => 'required',
                    'clientOptions' => array(
                        'validateOnSubmit' => true,
                        'afterValidate' => 'js:myFunc',
                    ),
                ));
                ?>

                ------Your form fields------------

                ------Your form fields------------

                ------Your form fields------------


               <?php $this->endWidget(); ?>

现在,您的 myFunc 代码:

Now, Your myFunc code:

        <script type="text/javascript" charset="utf-8">
            function myFunc(form, data, hasError)
            {

                if (hasError) 
                {
                    var errors='';
                    $.each(data, function(obj)
                    {
                        errors+=data[obj][0]+"\n";
                    });
                    alert(errors);

                    // Do what ever you want

                    return true;
                }
            }
        </script> 

这篇关于在弹出框中提交错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆