1

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>";
          }
  }
8
  • U need to use <?php echo validation_errors(); ?> in view this will tell u what actual u r getting. Commented Oct 9, 2016 at 12:54
  • 1
    You've fallen for the trap of using compressed words ( for want of a better term) and then falling back to using full words... IN your rules where you have the entry matches[password], where is password? Is it not supposed to be curPword or currentPassword, which reads a whole lot nicer. The extra Keypresses required to spell out words in full dont (does not) cost you anything... Commented Oct 9, 2016 at 13:04
  • @TimBrownlaw thank you for your answer how can i change it sir ?. . i dont understand what hppen .. can you answer ? Commented Oct 9, 2016 at 13:05
  • @devpro hello sir, thanks for your answer. i have no errors in my console. do i need to do echo valid_errors(); ? where would i put it ? inside the false ? Commented Oct 9, 2016 at 13:06
  • Add this in view file this will tell u the actual error Commented Oct 9, 2016 at 13:07

1 Answer 1

3

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]

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much sir.. i've learned something in you. echo validation_errors();
@jc-john glad to help u

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.