Jc John Jc John - 15 days ago 7x
Ajax Question

codeigniter form_validation returning false

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 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 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 class="col-sm-8 ajax_pass_result"></div>
<button onclick="changepass(event)" class="btn btn-success btn-sm "><i class="fa fa-refresh"></i> Update Password</button>

my ajax:

function changepass(e) {
type: "POST",
url: "<?php echo site_url('manager/profile/update_password') ?>",
data: $("#pass_form").serialize(),
success: function(res) {



and my controller where the form_validation always returns false:

public function update_password() {

$config = array(
'field' => 'curPword',
'label' => 'curPword',
'rules' => 'trim|required|callback_oldpassword_check' // Note: Notice added callback verifier.
'field' => 'confPword',
'label' => 'confPword',
'rules' => 'trim|required|matches[password]'
'field' => 'newPword',
'label' => 'newPword',
'rules' => 'trim|required'

if ($this->form_validation->run() == FALSE) {
echo 'Error in password fields !';
else {
$message = "No Error ";
echo "<script type='text/javascript'>alert('$message');</script>";


You just need to change rule for confirm password validation as:

array( 'field' => 'confPword', 'label' => 'confPword', 'rules' => 'trim|required|matches[curPword]' ),

What actually you are using, you are using matches[password] but your password field name is matches[curPword]