任何 IE 或 Firefox 均不支持 JQuery 验证插件 < 3.6 但适用于 Chrome 和 Safari

发布于 2024-12-10 15:21:11 字数 1843 浏览 0 评论 0 原文

这是我的第一篇文章,如果我能尽快从您那里得到解决方案,我将不胜感激。提前致谢。 :)

我在我的应用程序中使用 JQuery 验证插件。我有一个注册表单并使用 .submit() 方法提交表单。但是当我尝试从 Mozilla 或 IE 提交相同的表单时,它提交了表单但没有经过验证。简而言之,在没有验证的情况下,我在 y DB 中获取了垃圾数据。

我正在附上我的 .JS 文件,请务必查看并让我知道我是否做错了什么。

home.js

//验证规则

    $('#signup-form').validate({

        rules: {
            'firstname':       { required:  true },
            'lastname':        { required:  true },
            'email':           { required:  true,
                                 email:     true,
                                 remote:  { url:  siteurl+'ajax/checkemail',
                                            type: 'post' }},
. 
.
.
.
messages: {
            'firstname':       { required:  'Please enter your first name' },
            'lastname':        { required:  'Please enter your last name' },
            'email':           { required:  'Please enter your email address',
                                 email:     'Your email address is invalid',
                                 remote:    'The email you chose is already in use' },

    .
    .
    .       
    errorLabelContainer: $(".fail-message")

    });.

//单击注册确定按钮

            $("#signup-ok-btn").click(function(){           
              $("#signup-form").submit();
              return false;         
             });

//注册表单提交

     $('#signup-form').submit(function(){

        //If the form is invalid
        if ($('#signup-form').valid()){             
            return true;                                    
        } else {                
            //Show errors
            $('#signup-form-fail').fadeIn(300);
            return false;                   
        }

    });

我添加了一些与提交表单相关的代码片段。如果我在某个地方出错或者存在一些绑定问题,你能指导我吗?

This is my first post and will appreciate if I can get the solution from you asap. Thanks in advance. :)

I am using JQuery validation plugin in my application. I have a signup form and uses .submit() method to submit the form. But when I try to submit the same form from Mozilla or IE,it submits the form but doesn't go through the validation. So in short w/o validation, I am getting garbage data in y DB.

I am attaching my .JS file and please have to look and let me know if I am doing something wrong.

home.js

//Validation rules

    $('#signup-form').validate({

        rules: {
            'firstname':       { required:  true },
            'lastname':        { required:  true },
            'email':           { required:  true,
                                 email:     true,
                                 remote:  { url:  siteurl+'ajax/checkemail',
                                            type: 'post' }},
. 
.
.
.
messages: {
            'firstname':       { required:  'Please enter your first name' },
            'lastname':        { required:  'Please enter your last name' },
            'email':           { required:  'Please enter your email address',
                                 email:     'Your email address is invalid',
                                 remote:    'The email you chose is already in use' },

    .
    .
    .       
    errorLabelContainer: $(".fail-message")

    });.

//Click sign up OK button

            $("#signup-ok-btn").click(function(){           
              $("#signup-form").submit();
              return false;         
             });

//Signup form submit

     $('#signup-form').submit(function(){

        //If the form is invalid
        if ($('#signup-form').valid()){             
            return true;                                    
        } else {                
            //Show errors
            $('#signup-form-fail').fadeIn(300);
            return false;                   
        }

    });

I have added some snippets of my code related to submit the form. Can you please guide me if I m going wrong somewhere if there is some binding problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2024-12-17 15:21:11

您应该在验证代码中使用 submitHandler

$('#signup-form').validate({
   rules: {
     'firstname': { required: true },
     'lastname': { required: true },
     'email': {
        required: true,
        email: true,
        remote: {
           url: siteurl+'ajax/checkemail',
           type: 'post'
        }
     }
   },

   messages: {
     'firstname': { required: 'Please enter your first name' },
     'lastname': { required: 'Please enter your last name' },
     'email': {
        required: 'Please enter your email address',
        email: 'Your email address is invalid',
        remote: 'The email you chose is already in use'
     }
   },

   errorLabelContainer: $(".fail-message"),

   submitHandler: function(form) {
      ...WHAT YOU WANT TO HAPPEN WHEN THE FORM IS SUBMITTED...
      form.submit();
   }
});

您不应该手动将任何内容附加到提交按钮;验证插件会为您处理这一切。

以下是 jQuery 验证插件的官方文档: http://docs.jquery.com/Plugins/Validation 。那里有大量的好信息和例子。

You should be using the submitHandler inside of your validate code.

$('#signup-form').validate({
   rules: {
     'firstname': { required: true },
     'lastname': { required: true },
     'email': {
        required: true,
        email: true,
        remote: {
           url: siteurl+'ajax/checkemail',
           type: 'post'
        }
     }
   },

   messages: {
     'firstname': { required: 'Please enter your first name' },
     'lastname': { required: 'Please enter your last name' },
     'email': {
        required: 'Please enter your email address',
        email: 'Your email address is invalid',
        remote: 'The email you chose is already in use'
     }
   },

   errorLabelContainer: $(".fail-message"),

   submitHandler: function(form) {
      ...WHAT YOU WANT TO HAPPEN WHEN THE FORM IS SUBMITTED...
      form.submit();
   }
});

You shouldn't be attaching anything to the submit button manually; The validation plug-in handles this all for you.

Here's the official documentation for the jQuery Validation plug-in: http://docs.jquery.com/Plugins/Validation. Tons of good information and examples there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文