[eluser]skunkbad[/eluser]
OK, so I figured out how to make for external form validation callbacks. I'm not sure this is the best way, but it's what works. The key for my success was to use a model, in which I can store all the different callbacks as methods. I know to a MVC purist, I am probably committing the ultimate sin using a model for this purpose, but like I said before, it is what works. Should I have made a library? Well, maybe so. Anyways...
The form validation rule is set as normal, then inside the controller I put a method/function like this:
Code:
public function _usernameChecks($uname){
list($result , $error_string) = $this->data_checks->username($uname);
if($result === FALSE){
$this->form_validation->set_message('_usernameChecks', $error_string);
return FALSE;
}else{
return $result;
}
}
And the model, which currently only has one method (because it took me so long to figure out what to do to make this work) looks like this:
Code:
<?php
class Data_checks extends Model {
function username($uname){
if(strlen($uname) < MIN_CHARS_4_USERNAME){
$response[] = FALSE;
$response[] = 'Supplied <span class="redfield">%s</span> was too short.';
return $response;
}else{
//Check against user table
$user_table = $this->authentication->get_table('user_table');
$this->db->where('user_name', $uname);
$query = $this->db->get_where($user_table);
if ($query->num_rows() > 0){ //if user name already exists
$response[] = FALSE;
$response[] = 'Supplied <span class="redfield">%s</span> already exists.';
$query->free_result();
return $response;
}else{
$response[] = $uname;
$response[] = '';
$query->free_result();
return $response;
}
}
}
}
If anyone has any other ideas, let me know.