HTML页面 - Hii,我是Keshav Bhatt。 我,我在我的表单中添加匹配两个电子邮件地址验证与CI中的jQuery验证。我,我没有得到错误我的数据通过AJAX,但两个电子邮件匹配验证在客户端不起作用。在我的JQuery代码的HTML代码下面。请解决我所犯的错误?
<!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="someone@example.com"/>
</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="someone@example.com"/>
</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 :(得分: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>