Can anyone help me why is my code returning if ($this->form_validation->run() == FALSE)
. I am a begginer in codeigniter and i want to use form_validation to match the rules of changing password. I only want is to return the statement form_validation to true so that i can proceed on updating in database.
I already loaded form_validation,url etc. My callback_oldpassword code works fine so,i dont need to cover it in my question. So nevermind the callback it already returns true.
what i want is to focus on my password match ?. i think it is there the wrong doing. Can anyone help me find out what happens. ? to return the form_validation into true based on the rules that i've declared.
Here is my form:
<form id="pass_form" class="form-horizontal">
<?php $userid = ($this->session->userdata['logged_in']['user_id']); ?>
<input type="hidden" name="userid" id="userid" value="<?php echo $userid ?>" />
<div class="form-group">
<label class="control-label col-sm-3" for="curPword">Current Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" name="curPword" id="curPword" placeholder="Enter current password" required />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="newPword">New Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" name="newPword" id="newPword" placeholder="Enter new password" required />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="confPword">Confirm Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" name="confPword" id="confPword" placeholder="Confirm new password" required />
</div>
<div class="col-sm-8 ajax_pass_result"></div>
</div>
<button onclick="changepass(event)" class="btn btn-success btn-sm "><i class="fa fa-refresh"></i> Update Password</button>
</form>
my ajax:
function changepass(e) {
e.preventDefault();
jQuery.ajax({
type: "POST",
url: "<?php echo site_url('manager/profile/update_password') ?>",
data: $("#pass_form").serialize(),
success: function(res) {
$(".ajax_pass_result").html(res);
}
});
}
and my controller where the form_validation always returns false:
public function update_password() {
$config = array(
array(
'field' => 'curPword',
'label' => 'curPword',
'rules' => 'trim|required|callback_oldpassword_check' // Note: Notice added callback verifier.
),
array(
'field' => 'confPword',
'label' => 'confPword',
'rules' => 'trim|required|matches[password]'
),
array(
'field' => 'newPword',
'label' => 'newPword',
'rules' => 'trim|required'
));
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE) {
echo 'Error in password fields !';
}
else {
unset($_POST);
$message = "No Error ";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}