Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 引导模式注册表验证并提交_Javascript_Php_Jquery_Forms_Twitter Bootstrap - Fatal编程技术网

Javascript 引导模式注册表验证并提交

Javascript 引导模式注册表验证并提交,javascript,php,jquery,forms,twitter-bootstrap,Javascript,Php,Jquery,Forms,Twitter Bootstrap,我试图验证一个引导模式注册表单并提交到PHP页面。下面是我的jquery代码。我是jquery的新手,所以没能成功 <script> $(function () { //twitter bootstrap script $("button#submit").click(function () { $(document).ready(function () { $('#register-form').for

我试图验证一个引导模式注册表单并提交到PHP页面。下面是我的jquery代码。我是jquery的新手,所以没能成功

<script>
    $(function () {
//twitter bootstrap script
        $("button#submit").click(function () {
            $(document).ready(function () {
                $('#register-form').formValidation({
                    framework: 'bootstrap',
                    excluded: ':disabled',
                    icon: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },
                    fields: {
                        rfullname: {
                            validators: {
                                notEmpty: {
                                    message: 'The username is required'
                                }
                            }
                        },
                        rpassword: {
                            validators: {
                                notEmpty: {
                                    message: 'The password is required'
                                }
                            }
                        }
                    }
                });
            });

            $.ajax({
                type: "POST",
                url: "process.php",
                data: $('form#register-form').serialize(),
                success: function (msg) {
                    //$("#thanks").html(msg)
                    $("#login-modal").modal('hide');
                    bootbox.alert(msg);
                    $('#register-form').each(function () {
                        this.reset();
                    });
                },
                error: function () {
                    alert("failure");
                }
            });
        });
    });
</script>

$(函数(){
//twitter引导脚本
$(“按钮提交”)。单击(函数(){
$(文档).ready(函数(){
$(“#注册表格”).formValidation({
框架:“bootstrap”,
已排除:':已禁用',
图标:{
有效:“glyphicon glyphicon ok”,
无效:“glyphicon glyphicon删除”,
正在验证:“glyphicon glyphicon刷新”
},
字段:{
rfullname:{
验证器:{
注意:{
消息:“用户名是必需的”
}
}
},
rpassword:{
验证器:{
注意:{
消息:“密码是必需的”
}
}
}
}
});
});
$.ajax({
类型:“POST”,
url:“process.php”,
数据:$('form#register form')。序列化(),
成功:功能(msg){
//$(“#谢谢”).html(msg)
$(“#登录模式”).modal('hide');
bootbox.alert(msg);
$(“#注册表形式”)。每个(函数(){
这是reset();
});
},
错误:函数(){
警报(“故障”);
}
});
});
});
登记表是

<form id="register-form" style="display:none;" data-async  method="post" role="form">
   <div class="modal-body">
      <input id="rfullname" class="form-control" name="mname" type="text" placeholder="Your Full Name">
      <input id="remail" class="form-control" name="email" type="text" placeholder="E-Mail">
      <input id="rpassword" class="form-control" name="password" type="password" placeholder="Password">
   </div>
   <div class="modal-footer">
      <div>
         <button type="submit" name="submit" id="submit" class="btn btn-primary btn-lg btn-block">Register</button>
      </div>
      <div>
         <button id="register_login_btn" type="button" class="btn btn-link">Log In</button>
         <button id="register_lost_btn" type="button" class="btn btn-link">Lost Password?</button>
      </div>
   </div>
</form>

登记
登录
密码丢失了?
此表格应在验证后提交数值

试试这个

  <script>
            $(document).ready(function() {
                     $('#register-form').formValidation({
                        framework: 'bootstrap',
                        excluded: ':disabled',
                        icon: {
                            valid: 'glyphicon glyphicon-ok',
                            invalid: 'glyphicon glyphicon-remove',
                            validating: 'glyphicon glyphicon-refresh'
                        },
                    fields: {
                        rfullname: {
                            validators: {
                                notEmpty: {
                                    message: 'The username is required'
                                }
                            }
                        },
                        rpassword: {
                            validators: {
                                notEmpty: {
                                    message: 'The password is required'
                                }
                            }
                        }
                    },
                    submitHandler : function(validator, form, submitButton) {
                                        saveData();
                                    }
                });
             });

               function saveData(){
                        $.ajax({
                            type: "POST",
                        url: "process.php",
                        data: $('form#register-form').serialize(),
                            success: function(msg){
                                  //$("#thanks").html(msg)
                                $("#login-modal").modal('hide');
                                bootbox.alert(msg);
                                $( '#register-form' ).each(function(){
                                 this.reset();
                                 });    
                            },
                        error: function(){
                            alert("failure");
                            }
                            });
              }
    </script>

$(文档).ready(函数(){
$(“#注册表格”).formValidation({
框架:“bootstrap”,
已排除:':已禁用',
图标:{
有效:“glyphicon glyphicon ok”,
无效:“glyphicon glyphicon删除”,
正在验证:“glyphicon glyphicon刷新”
},
字段:{
rfullname:{
验证器:{
注意:{
消息:“用户名是必需的”
}
}
},
rpassword:{
验证器:{
注意:{
消息:“密码是必需的”
}
}
}
},
submitHandler:函数(验证器、表单、submitButton){
saveData();
}
});
});
函数saveData(){
$.ajax({
类型:“POST”,
url:“process.php”,
数据:$('form#register form')。序列化(),
成功:功能(msg){
//$(“#谢谢”).html(msg)
$(“#登录模式”).modal('hide');
bootbox.alert(msg);
$(“#注册表形式”)。每个(函数(){
这是reset();
});    
},
错误:函数(){
警报(“故障”);
}
});
}

我找到了问题的答案

<script>
$(function() {

  $('form[name="registor"]').find('input,select,textarea').not('[type=submit]').jqBootstrapValidation({

    submitSuccess: function ($form, event) {

      $.ajax({
                type: "POST",
            url: "process.php",
            data: $('form#register-form').serialize(),
                success: function(msg){
          // just to confirm ajax submission
          $("#login-modal").modal('hide');
                    bootbox.alert(msg);
                    $( '#register-form' ).each(function(){
                     this.reset();
                     });},
            error: function(){
                alert("failure");
                }
                }); 

      // will not trigger the default submission in favor of the ajax function
      event.preventDefault();
    }

  });

});
</script> 

$(函数(){
$('form[name=“registor”]”)。查找('input,select,textarea')。而不是('type=submit]')。jqBootstrapValidation({
submitSuccess:函数($form,event){
$.ajax({
类型:“POST”,
url:“process.php”,
数据:$('form#register form')。序列化(),
成功:功能(msg){
//只是为了确认ajax提交
$(“#登录模式”).modal('hide');
bootbox.alert(msg);
$(“#注册表形式”)。每个(函数(){
这是reset();
});},
错误:函数(){
警报(“故障”);
}
}); 
//不会触发有利于ajax功能的默认提交
event.preventDefault();
}
});
});

感谢所有试图帮助我的人。

有任何错误吗?为什么要使用document.ready inside按钮单击事件处理程序?您使用哪个插件来验证表单?是的,文档就绪位置错误,因此不是免费的“调试/修复我的代码”服务。如果您无法解决?所有投反对票的蠢货都离你远点你能更专注于你所做的事吗,为什么等等?