在弹出框中提交错误?

编程入门 行业动态 更新时间:2024-10-19 22:29:20
本文介绍了在弹出框中提交错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如何在弹出对话框中显示表单中的验证错误?我想在弹出对话框中显示这些错误,而不是将其作为单独的 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:34:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047372.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框中   错误   在弹出

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!