function matches($str, $field) { if (!isset($_POST[$field])) { return FALSE; } $field = $_POST[$field]; return ($str !== $field) ? FALSE : TRUE; }
array( 'field' => 'password', 'label' => 'Password', 'rules' => 'trim|required|md5' ), array( 'field' => 'confirm_password', 'label' => 'Confirm Password', 'rules' => 'trim|matches[password]' )
array( 'field' => 'model[password]', 'label' => 'Password', 'rules' => 'trim|required|md5' ), array( 'field' => 'model[confirm_password]', 'label' => 'Confirm Password', 'rules' => 'trim|matches[model[password]]' )
class MY_Form_validation extends CI_Form_validation { //put your code here public function __construct($rules = array()) { parent::__construct($rules); } function matches($str, $field) { if (strpos($field,'[') !== FALSE) { $field_arr = explode('[', str_replace(']', '', $field)); if (!isset($_POST[$field_arr[0]])) { return FALSE; } $field_val = $this->get_arr_field_val($field_arr, $_POST[$field_arr[0]]); return ($str !== $field_val) ? FALSE : TRUE; } if (!isset($_POST[$field])) { return FALSE; } $field = $_POST[$field]; return ($str !== $field) ? FALSE : TRUE; } function get_arr_field_val($arr, $post_val) { for ($i = 0; $i < count($arr); $i++) { if (isset($arr[$i + 1])) { if (isset ($post_val[$arr[$i + 1]])) { $post_val = $post_val[$arr[$i + 1]]; } } } return $post_val; } }