Reputation: 13
My problem is when I click submit the form_validation->run() returns false
Here is my controller
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"));
}
}
Here is my view.................
<?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>
Upvotes: 1
Views: 1332
Reputation: 132
hi you have to first load view in separate function.this will be your code.
public function index()
{
$this->load->helper('form');
$this->load->view('your view name');
}
Upvotes: 2
Reputation: 107
i think you need to check that you click to the submit button then the validation
here is the code you need to change in your controller
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');
}
because of not checking is always false in validation i think it should help you
Upvotes: 0