drci47425 2016-10-09 12:50 采纳率: 100%
浏览 52
已采纳

codeigniter form_validation返回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>
    </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>";
          }
  }
  • 写回答

1条回答 默认 最新

  • du6333137 2016-10-09 13:12
    关注

    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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么