Jump to content


Unable to access an error message corresponding to your field name

set_rules

  • Please log in to reply
1 reply to this topic

#1 Sonelal Singh

Sonelal Singh

    Newbie

  • Members
  • Pip
  • 8 posts

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.

 

 

 

 

 

 

 

 

 

 



#2 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts
  • LocationUkraine

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 ");

 

 







Also tagged with one or more of these keywords: set_rules

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users