我有一个注册页面,其中有两个单选按钮,我是公司或我个人。如果我选择公司,则公司名称和注册号屏幕上将出现两个字段,如果我选择个人,则身份证明文件上将出现三个字段, 身份证号码和年收入
我遇到一个验证问题,因为选择个人后,如果我将标识字段留空,则不会给我适当的错误。
下面是我的代码
<script>
$(document).ready(function() {
var maxDate = new Date().getDate() - 6570;
$('#dob').datepicker({autoclose: true, todayHighlight: true,format: 'dd/mm/yyyy',endDate: new Date(new Date().setDate(maxDate))});
$('#dob1').datepicker({autoclose: true, todayHighlight: true,format: 'dd/mm/yyyy',endDate: new Date(new Date().setDate(maxDate))});
$('#industry').select2();
$('#industry1').select2();
$('#country').select2();
$('#annual_income').select2();
$('#identification_document').select2();
$('#designation1').select2();
$('#practices').select2();
$('#countryCode').select2();
$('#counCode').select2();
$('#sign_up').click(function () {
fname = $("#fname").val();
lname = $("#lname").val();
if($('#country').select2('data') != null){
country = $('#country').select2('data').text;
}else {
country = "";
}
if($('#countryCode').select2('data') != null){
code1 = $('#countryCode').select2('data').text;
}else {
code1 = "";
}
contact1 = $('#contactNo1').val();
email = $("#email").val();
client_iam = $('input[name=inlineRadioOptions]:checked').val();
company = $('#client_company').val();
companyreg = $('#client_company_reg').val();
identification_number = $('#identification_num').val();
if($('#identific ation_document').select2('data') != null){
identification_document = $('#identification_document').select2('data').text;
}else {
identification_document = "";
}
if($('#annual_income').select2('data') != null){
annual_income = $('#annual_income').select2('data').text;
}else {
annual_income = "";
}
password = $("#password").val();
cnf_password = $("#cnf_password").val();
role = "client";
var email_Format = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(!(email_Format).test(email)){
show_notification('error', 'Please enter email in abc@xyz.com format only!');
return false;
}
if (fname == "" || lname == "" || country == "" || code1 == "" || contact1 =="" || email == "" || password == "") {
show_notification("error", "Please enter all required fields");
}else if(($('input[name="inlineRadioOptions"]:checked').length == 0)) {
show_notification('error', 'Please select as you want to signup as a company or an individual.');
}else if(company == "" || companyreg == ""){
show_notification('error', "please enter company and registration number!!!"); //here is issue i am facing when i left identification_number blank it gives me company field error.
}else if(identification_number == ''){
show_notification('error', "enter identification number");
}else{
if (password != cnf_password) {
show_notification("error", "Password and confirm password doesn't match");
} else {
if(!$('#client_terms_checkbox').is(':checked')){
show_notification("error","Please accept terms & conditions");
}else {
$.ajax({
url: "reg",
type: "POST",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: {
fname: fname,
lname: lname,
country: country,
role: role,
company : company,
code: code1,
contact: contact1,
client_iam: client_iam,
companyreg:companyreg,
identification_document: identification_document,
identification_number: identification_number,
annual_income: annual_income,
email: email,
password: password,
postlogin: localStorage.postlogin
},
success: function (data) {
localStorage.removeItem("postlogin");
show_notification("success", "Registered Successfully");
setTimeout(function (result) {
window.location.href = data;
}, 1000);
},
error: function (data) {
show_notification("error", data.responseJSON.message);
}
});
}
}
}
});
});
</script>
任何帮助将不胜感激...
HTML代码:
<div class="card-body tab-content">
<div class="tab-pane active" id="first1">
<div class="form">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" style="border: 1px solid #ddd; padding: 5px;width: 100%;margin-top: 10px;" class="form-control" name="first_name" id="fname" >
<label style="font-size: 15px;" >First Name*</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" style="border: 1px solid #ddd; padding: 5px; width: 100%; margin-top: 10px;" class="form-control" id="lname" name="lname">
<label style="font-size: 15px;" >Last Name*</label>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group" style="margin-bottom: 20px;">
<select style="margin-top: 25px;" id="country" class="form-control " name="country">
<option value=""></option>
<option value=""> Brunei</option>
<option value=""> Cambodia</option>
<option value=""> Indonesia</option>
<option value=""> Laos</option>
<option value=""> Malaysia</option>
<option value=""> Myanmar</option>
<option value=""> Philippines</option>
<option value=""> Singapore</option>
<option value=""> Thailand</option>
<option value=""> Vietnam</option>
</select>
<label style="font-size: 15px;" for="">Select Country*</label>
</div>
</div>
<div class="col-md-2">
<div class="form-group" style="margin-bottom: 20px;">
<select style="margin-top: 25px;" id="countryCode" class="form-control select2-list" name="phone">
<option value=""></option>
<option value=""> +673</option>
<option value=""> +855</option>
<option value=""> +62</option>
<option value=""> +856</option>
<option value=""> +60</option>
<option value=""> +95</option>
<option value=""> +63</option>
<option value=""> +65</option>
<option value=""> +66</option>
<option value=""> +84</option>
</select>
<label style="font-size: 15px;" for="">Country code</label>
</div>
</div>
<div class="col-md-4">
<div class="form-group" style="margin-bottom: 20px;">
<label style="font-size: 15px;" for="">Contact Number*</label>
<input type="number" style="border: 1px solid #ddd; padding: 5px;width: 100%;margin-top: 13px;" class="form-control" name="phone1" id="contactNo1" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-12" style="padding-left: 0;">
<div class="form-group">
<div class="col-md-1" style="padding-left: 0px;padding-right: 0;text-align: center;"> I am</div>
<div class="col-md-11" style="padding-left: 0px;">
<label class="radio-inline radio-styled" style="margin-right: 20px;" >
<input style="" type="radio" name="inlineRadioOptions" id="company_redio" value="company"><label for="">a company</label>
</label>
<label class="radio-inline radio-styled">
<input type="radio" name="inlineRadioOptions" id="individual_redio" value="an individual"><label for="">an individual</label>
</label>
</div><!--end .col -->
</div><!--end .form-group -->
</div>
</div>
{{--Start company--}}
<div class="row" id="company_div" style="display: none;padding-top: 10px;">
<div class="col-md-6">
<div class="form-group">
<input type="text" style="border: 1px solid #ddd; padding: 5px; width: 100%; margin-top: 10px;" class="form-control" id="client_company" name="client_company_name">
<label style="font-size: 15px;" for="client_company">Company Name*</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" style="border: 1px solid #ddd; padding: 5px; width: 100%; margin-top: 10px;" class="form-control" id="client_company_reg" name="client_company_reg">
<label style="font-size: 15px;" for="client_company_reg">Registration Number*</label>
</div>
</div>
</div>
{{--End Company--}}
{{--Start individual--}}
<div class="row" id="individual_div" style="display: none;padding-top: 10px;">
<div class="col-md-6">
<div class="form-group">
<select style="margin-top: 25px;" id="identification_document" class="form-control " name="identification_document">
<option value=""> NRIC</option>
<option value=""> FIN</option>
<option value=""> Passport</option>
</select>
<label style="font-size: 15px;" for="identification_document">Identification Document*</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" style="border: 1px solid #ddd; padding: 5px; width: 100%; margin-top: 10px;" class="form-control" id="identification_num" name="identification_number">
<label style="font-size: 15px;" for="identification_number">Identification Number*</label>
</div>
</div>
</div>
<div class="row" id="individual_annual_div" style="display: none;padding-top: 5px;">
<div class="col-md-6">
<div class="form-group">
<select style="margin-top: 25px;" id="annual_income" class="form-control " name="annual_income">
<option value=""> <10,000 SGD</option>
<option value=""> 10,000 - 30,000 SGD</option>
<option value=""> >30,000 SGD</option>
</select>
<label style="font-size: 15px;" for="annual_income">Annual income</label>
</div>
</div>
</div>
{{--End individual--}}
<div class="row" style="padding-top: 20px">
<div class="col-md-12">
<div class="form-group">
<input type="email" style="border: 1px solid #ddd; padding: 5px; width: 100%; margin-top: 10px;" class="form-control" id="email" name="email">
<label style="font-size: 15px;" for="email">Email*</label>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="password" style="border: 1px solid #ddd; padding: 5px; width: 100%; margin-top: 10px;" class="form-control" id="password" name="password">
<label style="font-size: 15px;" for="Password">Password*</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="password" style="border: 1px solid #ddd; padding: 5px; width: 100%; margin-top: 10px;" class="form-control" id="cnf_password" name="cnf_password">
<label style="font-size: 15px;" for="cnf_password">Confirm Password*</label>
</div>
</div>
</div>
<div class="row" style="padding-left: 18px">
<div class="checkbox checkbox-styled tile-text">
<label>
<input type="checkbox" id="client_terms_checkbox">
<span> I agree with Quesmi’s <u><a href="termsofuse">Terms of Use</a></u> and <u><a href="privacypolicy">Privacy Policy</a></u>.</span>
</label>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;">
<button type="submit" class="btn btn-primary" style="width: 100%;margin-top: 20px;border-color: #FF0000;background-color: #FF0000;" id="sign_up">Sign Up </button>
</div>
</div>
</div><!--end .card-body -->
</div>