如何将jQuery验证集成到多步骤表单中

如何将jQuery验证集成到多步骤表单中,jquery,Jquery,现在的问题是,我在一个名为php4ever的网站上下载了一个多步骤表单。单击next(下一步)时,我希望字段集在移动到“下一个字段集”之前通过jquery验证,直到注册表单的最后一步。这是密码 CSS代码 .container { position: relative; } .onboarding-wrapper-inner { width: 800px; max-width: 100%; background-color: #ffffff; box-sh

现在的问题是,我在一个名为php4ever的网站上下载了一个多步骤表单。单击next(下一步)时,我希望字段集在移动到“下一个字段集”之前通过jquery验证,直到注册表单的最后一步。这是密码

CSS代码

.container {
    position: relative;
}
.onboarding-wrapper-inner {
    width: 800px;
    max-width: 100%;
    background-color: #ffffff;
    box-shadow: 2px 2px 12px rgb(0 0 0 / 10%);
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 15px;
    overflow: hidden;
    transform: translate(-50%, 5%);
    transition: .5s ease-in-out;
}
.onboarding-form {
    width: 100%;
    padding: 2.5rem 2rem;
    position: relative;
}
   
/*form-head*/
.form-head h1 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 20px;
    font-family: "Roboto", "Poppins", sans-serif;
}
fieldset {
    width: 100% !important;
}
fieldset .fieldset-head {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 30px;
    color: var(--primary-dark);
    width: 100%;
}
fieldset h2 {
    font-size: 1rem;
    margin-bottom: 20px;
}
fieldset p {
    margin-bottom: 40px;
}
fieldset p b {
    color: var(--primary-dark);
}

/*General input styling*/
.form-control {
    margin-bottom: 12px;
    position: relative;
}
input, input[type="text"], input[type="email"], 
input[type="password"], #secQtn {
    outline: none;
    border: 1px solid #999999;
    height: 45px;
    border-radius: 5px;
    width: 100%;
    padding-left: 10px;
    padding-right: 10px;
    color: var(--grey-dark);
    font-family: "Roboto", "Poppins", sans-serif;
    font-size: 14px;
}
select#secQtn  {
    -webkit-appearance: none;
    background-image: url(../img/chevron-down.png);
    background-repeat: no-repeat;
    background-position: right 2% bottom 45%;
    background-size: 20px;
    cursor: pointer;
}
input::placeholder {
    color: #7f7f7f;
    font-family: "Roboto", "Poppins", sans-serif;
    font-size: 14px;
}
label {
    display: block;
    margin-bottom: 5px;
}
label span {
    color: red;
}
.psswrd_group {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    width: 100%;
}
.psswrd_group div {
    flex: 1;
}
.psswrd_group > div:first-child {
    margin-right: 10px;
}
.psswrd_group > div:nth-child(2) {
    margin-left: 10px;
}


/*buttons*/
#btn-wrapper {
    width: 100%;
    display: block;
    margin-top: 25px;
    margin-bottom: 25px;
}
#btn-wrapper button {
    display: inline-block;
}

/*=== Buttons ===*/
.form-btn {
    background-color: var(--primary);
    height: 48px;
    border-radius: 5px;
    font-size: 1rem;
    color: #ffffff;
    text-align: left;
    padding-left: 10px;
    padding-right: 10px;
    cursor: pointer;
    transition: .5s ease-in-out;
}


/* Signup */
.signUp {
    height: 720px;
}
.intl-tel-input .country-list,
.country-select .country-list {
    width: 448px;
    border-radius: 5px;
    margin:3px 0 0 -1px;
}
.intl-tel-input .country-list::-webkit-scrollbar,
.country-select .country-list::-webkit-scrollbar {
    width: 7px;
    background-color: #f1f1f1;
}
.intl-tel-input .country-list::-webkit-scrollbar-thumb,
.country-select .country-list::-webkit-scrollbar-thumb {
    background-color: #BFBFBF;
    border-radius: 50px;
}


/* validation styling */
label.error, #error-msg {
    color: red;
    position: absolute;
    top: 0;
    right: 0;
}
input.error {
    border: 1px solid red;
}
.psswrd_group label.error {
    position: relative;
}
.hide {
    display: none; }
    #error-msg {
    color: red;
}
/*#valid-msg {
    color: #00C900;
}*/
#phone-error {
    top: -25px;
}

/* Multiple steps form */
#registration fieldset:not(:first-of-type) {
    display: none;
}
JQUERY验证代码

$(document).ready(function() {
    jQuery.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-z]+$/i.test(value);
      }, "Letters only please");    
    
    $("#registration").validate({
        rules: {
            fname: {
                required: true,
                fname: true,
                lettersonly: true
            },
            sname: {
                required: true,
                sname: true
            },
            email: {
                required: true,
                email: true
            },
            phone: {
                required: true,
            },
            password: {
                required: true,
                minlength: 8,
            },
            cpassword: {
                required: true,
                equalTo: '#password'
            }
        },
        messages: {
            fname: {
                required: 'Please first name is required.',
                nowhitespace: 'No whitespace',
                lettersonly: 'Only letters'
            },
            sname: {
                required: 'Please surname is required.',
                sname: true
            },
            email: {
                required: 'Enter an email address.',
                email: 'Please enter a <em>valid</em> email address.'
            },
            password: {
                required: 'Please enter Password!',
                minlength: 'Atleast 8 characters.'
            },
            cpassword: {
                required: 'Confirm Password.',
                equalTo: 'Enter the same password!'
            }
        },
        submitHandler: function() {
            $successMsg.show();
        }
    
    });
});
我的网站 顺便说一句,由于某些原因,“下一步”按钮没有显示,但它在那里

$(document).ready(function(){  
    var form_count = 1, form_count_form, next_form, total_forms;
    total_forms = $("fieldset").length;  
    $(".next").click(function(){
          let prev = $(this).closest("fieldset").attr('id');
          let next = $('#'+this.id).closest('fieldset').next('fieldset').attr('id');
          $('#'+next).slideToggle(700);
          $('#'+prev).hide(700);
          setProgressBar(++form_count);
    }); 
    
    $(".prev").click(function(){
          let current = $(this).closest("fieldset").attr('id');
          let prev = $('#'+this.id).closest('fieldset').prev('fieldset').attr('id');
          $('#'+prev).slideToggle(700);
          $('#'+current).hide(700);
          setProgressBar(--form_count);
    }); 
  
    setProgressBar(form_count);  
    function setProgressBar(curStep){
      var percent = parseFloat(100 / total_forms) * curStep;
      percent = percent.toFixed();
      $(".progress-bar")
        .css("width",percent+"%")
        //.html(percent+"%");   
    } 
  });