2016-10-09 13 views
1

誰でも私のコードがif ($this->form_validation->run() == FALSE)を返すのを助けることができますか?私はcodeigniterの初心者であり、私はform_validationを使用してパスワードを変更するルールに一致させたい。私はデータベース内の更新を続行できるように、文form_validationをtrueに戻すだけです。codeigniter form_validation falseを返す

私はすでにform_validation、urlなどを読み込んでいます。 私のcallback_oldpasswordコードはうまく動作しますので、私の質問でそれをカバーする必要はありません。だから、すでに返されているコールバックを忘れないでください。

私はパスワードマッチに焦点を当てていますか?私はそれが間違っていると思う。誰も私が何が起こるかを見つけるのを助けることができます。 ?宣言したルールに基づいてform_validationを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> 

私の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); 

    } 
    }); 

} 

とform_validationは常に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>"; 
      } 
    } 
+0

であるPHPのエコーvalidation_errorsは();? ?>これは実際にどのような実際のu rを得るかを示します。 – devpro

+1

あなたは圧縮された単語を使うという罠に陥ってしまいました(より良い言葉のために)。そして完全な単語を使うことに落ちました...あなたのエントリーが[パスワード]と一致するあなたのルールでは、パスワードはどこですか?それはcurPwordまたはcurrentPasswordであるはずがありません。余分なKeypressesは完全に言葉を綴る必要はありません(あなたは何もかかりません)... – TimBrownlaw

+0

@TimBrownlaw私はそれをどのように変更することができますあなたの答えに感謝? 。あなたは何を答えてくれますか? –

答えて

3

パスワード確認を次のように確認してください:

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

実際に使用している何を、あなたはmatches[password]を使用していますが、パスワードのフィールド名はUが<使用する必要がmatches[curPword]

+0

ありがとうございます。私はあなたの中で何かを学んだ。 echo validation_errors(); –

+0

@ jc-johnあなたを助けてうれしい – devpro

関連する問題