我的问题是当我点击提交form_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 :(得分:2)
嗨,你必须首先在单独的函数中加载视图。这将是你的代码。
public function index()
{
$this->load->helper('form');
$this->load->view('your view name');
}
答案 1 :(得分: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');
}
因为在验证时不检查总是错误的 我认为它应该对你有帮助