Welcome Guest, Not a member yet? Register   Sign In
Form Validation - Callback to a Model?
#2

(This post was last modified: 02-01-2018, 04:31 AM by Zeff.)

(02-01-2018, 12:56 AM)minsk832 Wrote: Hello,
my User_model have a public method called is_unique_email($email). This method checks if a user has a uniqe mail adress with some status flag checks. This is also the reason why I can't use the standard is_unique validation rule from CodeIgniter.

I'm using a form_validation.php with config array for my validation rule groups. My question ist: How can I call the model method for checking the new users e-mail adress? I searched and tried so many things, but nothing work. My preferred call would be with | pipe  separator.

Like: trim|required|max_length[70]|valid_email|<~ here comes the model callback ~>

Is there any solution for this callback or is there no way and I have to extend the Form_validation system library?

Thanks in advance!

Hi Minsk832,

I've you're trying to shift form_validation to the model (I was inspired by Lonnie Ezell's MY_Model), maybe you're struggling with the same issue as I had: check 'use-thing-as-a-rule' and check  proper formatting (see https://forum.codeigniter.com/thread-69930.html).

You should update the validation method in your model to something like this:
PHP Code:
function is_unique_email($email)
{
 
   $this->form_validation->set_message('whatever_you_name_it''This email address is not unique!');
 
   $this->db->where('email',$email);
 
   $query $this->db->get('your_model_table');
 
   if ($query->num_rows() > 0){
 
       return true;
 
   }
 
   else{
 
       return false;
 
   }


Good luck!

Zeff
Reply


Messages In This Thread
RE: Form Validation - Callback to a Model? - by Zeff - 02-01-2018, 04:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB