Php codeigniter表单_验证返回错误

Php codeigniter表单_验证返回错误,php,ajax,codeigniter,Php,Ajax,Codeigniter,谁能告诉我为什么我的代码返回如果($this->form\u validation->run()==FALSE)。我是codeigniter中的乞丐,我想使用form_验证来匹配更改密码的规则。我只想将语句form_validation返回为true,以便在数据库中继续更新 我已经加载了表单验证、url等。 我的密码很好用,所以我不需要在我的问题中涉及它。因此,不管回调如何,它已经返回true 我想要的是关注我的密码匹配?。我认为这是错误的做法。有人能帮我弄清楚发生了什么事吗?根据我声明的规则将

谁能告诉我为什么我的代码返回
如果($this->form\u validation->run()==FALSE)
。我是codeigniter中的乞丐,我想使用form_验证来匹配更改密码的规则。我只想将语句form_validation返回为true,以便在数据库中继续更新

我已经加载了表单验证、url等。 我的密码很好用,所以我不需要在我的问题中涉及它。因此,不管回调如何,它已经返回true

我想要的是关注我的密码匹配?。我认为这是错误的做法。有人能帮我弄清楚发生了什么事吗?根据我声明的规则将表单_验证返回为true

这是我的表格:

<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>


您只需将确认密码验证的规则更改为:

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

您实际使用的是什么,您使用的是
匹配[password]
,但是您的密码字段名是
匹配[curPword]

您需要使用的,这将告诉您实际使用的是什么。您已经落入了使用压缩字(因为缺少更好的术语)然后又回到使用完整字的陷阱。。。在您的规则中,条目与[密码]匹配,密码在哪里?是不是应该是curPword或currentPassword,这样读起来好多了。完整拼写单词所需的额外按键不会(不会)让你付出任何代价…@TimBrownlaw谢谢你的回答,先生,我该怎么更改。我不明白你在说什么。。你能回答吗?@devpro你好,先生,谢谢你的回答。我的控制台中没有错误。是否需要执行echo valid_errors()?我该把它放在哪里?在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>";
          }
  }
array( 'field' => 'confPword', 'label' => 'confPword', 'rules' => 'trim|required|matches[curPword]' ),