This is a working example, which more or less confirms that your code should work:
<?php // Test DB /******************************************** CREATE TABLE IF NOT EXISTS `some_table` ( `id` int(11) NOT NULL, `some_value` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `some_table` (`id`, `some_value`) VALUES (1, 10), (2, 20); *********************************************/ class Test_validation extends CI_Controller { public function index() { $this->load->library('form_validation'); $this->form_validation->set_rules('field_1', 'Field One', 'required|callback__field_one_checker[some_table.id]'); if ($this->form_validation->run() == FALSE) { echo 'either no post submitted, or validation failed'; if(validation_errors()) { echo validation_errors(); } } else { echo 'success'; } echo '<form action="#" method="post"> <input type="text" name="field_1" value="" /> <input type="submit" value="submit" /> </form>'; } function _field_one_checker($field_one, $table_column) { /* THIS ALSO WORKS list($table_name, $column) = explode('.', $table_column); if($query = $this->db ->where($column, $field_one) ->limit(1) ->get($table_name) ) */ $parts = explode('.', $table_column); if($query = $this->db ->where($parts[1], $field_one) ->limit(1) ->get($parts[0]) ) { if($query->num_rows() > 0) { return $field_one; } else { $this->form_validation->set_message('_field_one_checker', 'Your value was not an ID in some_table'); return FALSE; } } else { $this->form_validation->set_message('_field_one_checker', 'Query failed'); return FALSE; } } }
Thank You skunkbad. Of course your code works as expected. Everyone else code most likely works also. My code executes via AJAX instead of post-back(terminology?) I will have to break apart your code and plug the pieces in.
-Thank You,
Rich