⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Unable to access an error message corresponding to your field name



Sonelal Singh

Sonelal Singh
  • profile picture
  • Member

Posted 17 July 2015 - 06:49 AM

Hi,

 

I want to add email id validation such that email id must be of same domain not other domain.

 

For this I have written below code - 

 

 

        $this->load->library('grocery_CRUD');        
        $crud = new grocery_CRUD();
        $crud->set_theme('datatables');

        $crud->set_table('ci_users');

        $crud->set_subject('User');

        $crud->fields('empcode', 'firstname','lastname','email','password');

        $crud->required_fields('empcode', 'firstname', 'email', 'password');

       

        $crud->set_rules('email', 'Email', 'validate_emailid');

 

and I have defined "validate_emailid" function in same controller like below -

 
       function validate_emailid($email)
       {
               $str = explode("@",$str);       
               if($str[1]=='teamlease.com')
              {
                                echo $this->form_validation->set_message("validate_emailid","Other domain Email id are not allowed ");
                                return FALSE;
              }        
        }
 
but I am getting below error 
"Unable to access an error message corresponding to your field name Email.(validate_emailid)".
 
Can you guys help me to resolve this issue.Thanks in advance.

 

 

 

 

 

 

 

 

 

 


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 17 July 2015 - 10:00 AM

Hi! What i can see

1) custom callback validation function must starts with 'callback_'

2)No need "echo" in callback_validation_function - just return TRUE or FALSE. So remove word "echo"

And u in one case return FALSE but where are u return TRUE ?

Optionaly: in callback maybe u could write $this->form_validation->set_message(__FUNCTION__,"Other domain Email id are not allowed ");