• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED]Callback error

#1
i have this function in controller :

Code:
public function modificarecord($id){
        
         $data=[];
   
       $record=$this->clienti_model
           ->get_Clienti($id) ;
   
            
            $data['record']=$record;
       
       $this->form_validation->set_rules('id','Id',"required|trim|min_length[0]|max_length[10] " ,array('min_length'=>'Lunghezza minima id 0 caratteri', 'max_length'=>'Lunghezza massima id 10 caratteri','required'=>'id obbligatorio'));
       $this->form_validation->set_rules('ragione_sociale','Ragione_sociale',"required|callback_ragione_sociale_unique_on_update|trim|min_length[0]|max_length[100] " ,array('min_length'=>'Lunghezza minima ragione_sociale 0 caratteri', 'max_length'=>'Lunghezza massima ragione_sociale 100 caratteri','required'=>'ragione_sociale obbligatorio'));
       $this->form_validation->set_rules('citta','Citta',"trim|min_length[0]|max_length[100] " ,array('min_length'=>'Lunghezza minima citta 0 caratteri', 'max_length'=>'Lunghezza massima citta 100 caratteri'));
       $this->form_validation->set_rules('indirizzo','Indirizzo',"trim|min_length[0]|max_length[100] " ,array('min_length'=>'Lunghezza minima indirizzo 0 caratteri', 'max_length'=>'Lunghezza massima indirizzo 100 caratteri'));
       $this->form_validation->set_rules('cap','Cap',"trim|min_length[0]|max_length[5] " ,array('min_length'=>'Lunghezza minima cap 0 caratteri', 'max_length'=>'Lunghezza massima cap 5 caratteri'));
       $this->form_validation->set_rules('cf_o_piva','Cf_o_piva',"trim|min_length[0]|max_length[25] " ,array('min_length'=>'Lunghezza minima cf_o_piva 0 caratteri', 'max_length'=>'Lunghezza massima cf_o_piva 25 caratteri'));
       $this->form_validation->set_rules('telefono','Telefono',"trim|min_length[0]|max_length[15] " ,array('min_length'=>'Lunghezza minima telefono 0 caratteri', 'max_length'=>'Lunghezza massima telefono 15 caratteri'));
       $this->form_validation->set_rules('email','Email',"trim|min_length[0]|max_length[100]|valid_email|callback_email_unique_on_update " ,array('min_length'=>'Lunghezza minima email 0 caratteri', 'max_length'=>'Lunghezza massima email 100 caratteri','valid_email'=>'Inserisci una mail valida '));
         
       if($this->form_validation->run()){
           
         
         
           $res=$this->clienti_model
           ->editClienti(
              $this->input->post('id'),
              $this->input->post('ragione_sociale'),
              $this->input->post('citta'),
              $this->input->post('indirizzo'),
              $this->input->post('cap'),
              $this->input->post('cf_o_piva'),
              $this->input->post('telefono'),
              $this->input->post('email'),
                    1
           );

               if($res){
               
                  $this->load->view('templates/header' );

                  $this->load->view('templates/menu' );

                 
                  $this->load->view('clienti/clienti_modificato',$data );

                     
                  $this->load->view('templates/footer' );

                 
               }else{
                   
                 
                  $this->load->view('templates/header' );
                  $this->load->view('templates/menu' );
                 
                  $this->load->view('clienti/modifica_clienti',$data);
                     
                  $this->load->view('templates/footer' );
              }                  

       }else{
           
          $this->load->view('templates/header' );
          $this->load->view('templates/menu' );
                 
          $this->load->view('clienti/modifica_clienti',$data);
                     
          $this->load->view('templates/footer' );

                       
       }    
       
       
   }  

This is callback function :
Code:
        public function email_unique_on_update(){
            
            $id=$this->input->post('id');
            $email=$this->input->post('email');
            
            if($this->clienti_model
           ->email_unique_on_update($id,$email)){
                
                return TRUE;
                
            }else{
                $this->form_validation->set_message('email_unique_on_update', 'Il campo email è già presente ');
                return FALSE;
            }
        
        
        }
 
If i try to change the record i have this error :


Unable to access an error message corresponding to your field name Email.(email_unique_on_update )

if i cancel the control callback_email_unique_on_update i have this error :

Unable to access an error message corresponding to your field name Email.(valid_email )


How can i solve it ?
Reply

#2
it is my problem too
Reply

#3
You have to set the callback error something like this:

PHP Code:
$this->form_validation->set_message('email_unique_on_update''That email is already in use'); 

I belive (from memory) you set it in the callback itself, although that is just a vague memory and might not be right. Sorry to be a bit vague about it.

It is mentioned in the docs but it is also a bit vague (look at the bottom of this section after the last note):
https://www.codeigniter.com/user_guide/l...r-messages

Hope that helps,

Paul
Reply

#4
Sorry , i found the error yesterday night , the error is space before  " , the string must be without space .

Tanks for reply
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.