2014-01-10 63 views
1

我的問題是,當我點擊提交form_validation-> run()的返回falseform_validation-> run()的返回false笨

這裏是我的控制器

public function change_pass() 
{ 
$this->load->helper('form'); 
$this->load->library('form_validation'); 
$this->form_validation->set_rules('new_pass', 'New Password', 'required|matches[cnew_pass]'); 
$this->form_validation->set_rules('cnew_pass','Confirm Password','required|matches[new_pass]'); 

if($this->form_validation->run()==FALSE) 
{ 
die(print_r("Always go here")); 
} 
} 

這是我的觀點... ..............

<?php echo form_open('tickets/change_pass'); ?> 
    <center> 
<table> 

      <tr> 
       <td<label for="new_pass">New Password:</label> 
        <input type="password" name="new_pass" class="form-control"><?php echo form_error('new_pass');?> 
       </td> 
      </tr> 

      <tr> 
       <td<label for="cnew_pass">Confirm New Password:</label> 
        <input type="password" name="cnew_pass" class="form-control"><?php echo form_error('cnew_pass');?> 
       </td> 
      </tr> 
     </table> 

     <input type="submit" name="change" class="btn btn-success"> <input type="reset" class="btn btn-danger"> 
    </center> 
+0

將您的完整代碼放在此處。 – user2936213

+0

同樣在你的驗證規則中,只需刪除'matches [new_pass]'以確認密碼驗證 – user2936213

+0

匹配[cnew_pass]就足夠了不需要匹配[new_pass] –

回答

2

您好,您必須先在單獨的函數中加載視圖,這將是您的代碼。

public function index() 
    { 

     $this->load->helper('form'); 

     $this->load->view('your view name'); 

    } 
0

我認爲你需要檢查你點擊提交按鈕,然後驗證

以下是你需要在你的控制器改變

public function change_pass() { 
     $this->load->helper('form'); 
     $this->load->library('form_validation'); 

     if ($this->input->post('submit')) { 

     $this->form_validation->set_rules('new_pass', 'New Password', 'required|matches[cnew_pass]'); 
     $this->form_validation->set_rules('cnew_pass', 'Confirm Password', 'required|matches[new_pass]'); 

     if ($this->form_validation->run() == FALSE) { 
      die(print_r("Always go here")); 
     } 
     } 
     $this->load->view('change_pass'); 
    } 
因爲不檢查的

是代碼在驗證中始終爲假 我認爲它應該可以幫助您