[eluser]mddd[/eluser]
I think you are making things a little more complicated than neccessary. Remember you can have multiple validation callbacks on a field. In your code, you are checking to see if the email address isn't empty, is a real address, and doesn't already exist in the database.
The first two are normal callbacks you can do outside of your custom function:
Code:
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
This will do your first checks for you!
Then the last one: checking in the database. In your code, you load ALL your users and then say " $email_exist = $row->email_address " for every one of them. That doesn't actually DO anything! After the foreach you check against $email_exist. That means you only check if the address is the same as the last one in your database..
You should make your rule like this:
Code:
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_new_email');
And make a 'new_email' callback like this:
Code:
function new_email($str)
{
// return true if the address is indeed a new address
$this->db->where('email_address', $str);
$found = $this->db->get('players')->num_results(); // this returns the number of rows having the same address.
if ($found!=0)
return false; // more than 0 rows found. the callback fails.
else
return true; // 0 rows found. callback is ok.
}