2017-07-17 61 views
0

HTML Page-嗨,我是Keshav Bhatt。 我,我在表单中添加匹配两个电子邮件地址验证与CI中的jQuery验证。我没有收到错误,我的数据通过AJAX传递,但两个电子邮件匹配验证在客户端不起作用。低于HTML代码我的JQuery代码是。请给我任何解决方案我在做什么错误?我如何在codegniter中与jquery帮助匹配两个电子邮件地址

<!DOCTYPE html> 
<html lang="eng"> 
<html> 
<?php 
if (isset($this->session->userdata['logged_in'])) { 
    //header("location: http://localhost/ci/Form/user_login_process"); 
} 
?> 
<head> 
<title>Registration</title> 
<meta charset="utf-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets\css\style.css" /> 
<script type="text/javascript" src="<--?php echo $this->base_url();?>assets/js/validation.js"></script> 
</head>  
<body style="background-color:rgb(90,90,90);color:white " > 
<form id="reg_form" class="form-horizontal">  
<div class="container-fluid"> 
<div class="col-sm-2"></div>  
<div class="col-sm-8" style="background-color:white; margin-top: 120px; border-radius:20px;"> 
<button type="button" class="btn btn-info" style="margin-left:955px; margin-top:-200px;" onclick="location.href='http://localhost/ci/form/fetch'">Dash Board</button>  
<h2><legend style="color:#678;"><center>Enter Your Details Here</center><span class="req" >required *</span></legend></h2>  
<div class="form-group"> 
    <label for="username" class="control-label col-sm-2" ><span class="req">*</span>Username</label> 
    <div class="col-sm-10"> 
     <div class="input-group"> 
      <span class="input-group-addon"><i class="glyphicon glyphicon-user" aria-hidden="true"></i></span> 
      <input type="text" name="username" id="name" class="form-control" placeholder="Enter User Name"/> 
     </div> 
     <span class="error"><?php echo form_error('username'); ?></span> 
    </div> 
</div> 
<div class="form-group"> 
    <label for="password" class="control-label col-sm-2"><span class="req">*</span>Password</label> 
    <div class="col-sm-10"> 
     <div class="input-group"> 
      <span class="input-group-addon"><i class="glyphicon glyphicon-lock" aria-hidden="true"></i></span> 
      <input type="password" name="password" id="password" class="form-control" placeholder="Enter User Password"/> 
     </div> 
     <span class="error"><?php echo form_error('password'); ?></span> 
    </div> 
</div> 

<div class="form-group"> 
<label for="passconf" class="control-label col-sm-2"><span class="req">*</span>ConfirmPassword</label> 
<div class="col-sm-10"> 
<div class="input-group"> 
<span class="input-group-addon"><i class="glyphicon glyphicon-lock" aria-hidden="true"></i></span> 
<input type="password" name="passconf" id="passconf" class="form-control" placeholder="Confirm Users Password"/> 
</div> 
<span class="error"<?php echo form_error('passconf'); ?></span> 
</div> 
</div>  
<div class="form-group"> 
    <label for="email" class="control-label col-sm-2"><span class="req">* </span>Email</label> 
    <div class="col-sm-10"> 
     <div class="input-group"> 
      <span class="input-group-addon"><i class="glyphicon glyphicon-envelope" aria-hidden="true"></i></span> 
      <input type="text" name="email" id="email" class="form-control" placeholder="[email protected]"/> 
     </div> 
     <span class="error"><?php echo form_error('email'); ?><span> 
    </div> 
</div> 
</br> 
<div class="form-group"> 
    <label for="emailconf" class="control-label col-sm-2"><span class="req">* </span>ConfirmEmail</label> 
    <div class="col-sm-10"> 
     <div class="input-group"> 
      <span class="input-group-addon"><i class="glyphicon glyphicon-envelope" aria-hidden="true"></i></span> 
      <input type="text" name="emailconf" id="emailconf" class="form-control" placeholder="[email protected]"/> 
     </div> 
     <span class="error"><?php echo form_error('emailconf'); ?><span> 
    </div> 
</div> 
</br>  
</br> 
<div class="form-group row">  
    <div class="col-md-2"> </div>  
    <div class=" col-sm-8" style="text-align: center;"> 
     <button type="button" id="submit" value="submit" class="btn btn-success" style="margin-left: 16px;" >Submit</button> 
     <button type="reset" id="reset" name="reset" type="reset" class="btn btn-warning">Reset</button>  
     <a href="<?php echo base_url() ?>form/login" class="btn btn-danger">Cancel</a>  
    </div> 
    <div class="col-md-2"> </div> 
</div> 
</form>  

    <div class="col-sm-2"></div> 
</div>  
</div> 
</body> 
</html>  
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> 
<script type="text/javascript"> 
$(function(){ 
    $("#submit").click(function(){  
    $.ajax({ 
     url:"<?php echo site_url('form/new_user_registration') ?>", 
     type: 'POST', 
     data: $("#reg_form").serialize(), 
     success: function(res){ 
      alert("Data inserted successfully ?"); 
      $("#reg_form").html(res); 
      $('#username').val(''); 
      $('#password').val(''); 
      $('#passconf').val(''); 
      $('#email').val(''); 
      $('#emailconf').val(''); 
     },   
     error: function(){ 
      alert("Fail") 
     } 
    }); 
    return false; 
    }); 
}); 

$(document).on("click", "input[type='reset']", function(){ 
    $("select").trigger("change"); 
}); 

if($("#email").val() != $("#emailconf").val()) 
{ 
    alert("emails don't match"); 
} 
</script> 

Jquery script 

$(document).ready(function(){ 
$('#reg_form').validate({ 
    rules: { 
     email: 'required', 
     emailConf: { 
      equalTo: '#email' 
     } 
    } 
}), 
}); 

回答

0
$('#reg_form').validate({ 
rules: { 
    email: 'required', 
    emailconf: { 
     equalTo: '#email' 
    } 
} 
}), 

变化emailconf代替emailConf

<script type="text/javascript" src="<?--php echo $this->base_url();?>assets/js/validation.js"></script> 

<script type="text/javascript" src="<?php echo $this->base_url();?>assets/js/validation.js"></script> 
+0

我使用jQuery的外部,但它无法正常工作。我通过你的代码编辑了我的代码。这是我的外部Jquery。数据正确传递通过AJAX。 –

+0

检查您的浏览器控制台是否有任何问题? –

+0

包含JS'src =“<?php echo $ this-> base_url();?> assets \/js/validation.js'正确更改 –

相关问题