I'm stuck in this part. Everytime I correctly inputted the two fields with the same value it always returning password does not match.
I'm using ajax btw
Here's my controller:
Code:
$this->form_validation->set_rules("password", "password", "required");
$this->form_validation->set_rules("passwordconf", "password confirm", "matches[password]");
$data = array('userPassword' => password_hash($this->input->post('password'), PASSWORD_BCRYPT));
if ($this->form_validation->run()) {
$id = $this->input->post('id');
$response['success'] = true;
$response['message'] = "Successfully updated user password";
$response['page'] = base_url();
$this->user_model->userupdate($id, $data);
$response['id'] = $id;
$response['data'] = $data;
} else {
$response['success'] = false;
$response['errors'] = $this->form_validation->error_array();
}
Here's my ajax code:
Code:
$('#changePassForm').on('submit',function(event){
var userID = $('#userID').val();
var password = $('#password').val();
event.preventDefault();
$.ajax({
url: site_url('user/userUpdate'),
data: {id: userID, password: password},
type: 'post',
dataType: 'json',
success: function(response){
if(response.success === true){
console.log(response);
Materialize.toast(response.message, 2000, 'green');
setTimeout(function(){window.location.href = response.page;},3000);
}else{
if(response.success === false) {
if (response.errors) {
$.each(response.errors, function (key, val) {
$('input[name="' + key + '"]').next().html(val).addClass('has-error');
});
}
}
}
}
});
});
My view:
Code:
<div class="row" id="login-box" style="padding-top:140px">
<div class="col s4 offset-s4">
<div class="z-depth-5 card-panel blue-grey darken-4 white-text">
<h4 class="center">Change your password</h4>
<form autocomplete="off" id="changePassForm">
<div class="row">
<input type="hidden" id="userID" value="<?php echo $this->session->userdata('userID');?>">
<div class="input-field col s12">
<label for="last_name">Username</label>
<input id="username" name="username" type="text" style="font-size: 1.3rem;" class="" readonly value="<?php echo $this->session->userdata('userName');?>">
<span class="red-text"></span>
</div>
<div class="row">
<div class="input-field col s12">
<label for="password">New Password</label>
<input id="password" name="password" type="password" class="validate">
<span class="red-text"></span>
</div>
<div class="input-field col s12">
<label for="passwordconf">Confirm Password</label>
<input name="passwordconf" type="password" class="validate">
<span class="red-text"></span>
</div>
</div>
<div class="row" style="margin-bottom: 0px;">
<button type="submit" id="btn_changepass" class="btn red darken-4 waves-effect waves-light col s12"> Change Password</button>
</div>
</form>
</div>
</div>
</div>
I seem no error IMO. Where do I get wrong here.