• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form validation callback function doesn't work

#1
Hey,

I have a problem with a forum callback function. He run the script good but dont do the error message that is set in the callback function. I hope you guys can help me!

PHP Code:
public function unique_app_scanner_name($str$id){
      
$this->load->library('form_validation');
      
$uniqueNameCheck $this->db->query('SELECT * FROM `app_scanners` WHERE `Username` = "'$str .'" AND `id` NOT IN ('$id .')');

      if(
$uniqueNameCheck->num_rows() > 0){
        
$this->form_validation->set_message('unique_app_scanner_name'$this->lang->line('in_use'));
        return 
FALSE;
      }else{
        return 
TRUE;
      }
  }
  public function 
edit_app_scanner_validate($id){
    if(
$this->is_logged_in()){
      if(!empty(
$id)){
        
$appScannerCheck $this->db->query('SELECT * FROM `app_scanners` WHERE `id` = "'.$id.'" AND `UserId` = "'.$this->get_user_id().'" ');
        if(
$appScannerCheck->num_rows() > 0){
          
$appScannerResult $appScannerCheck->result_array();

          
$this->load->library('form_validation');

          
$this->form_validation->set_rules('firstName'$this->lang->line('firstName'), 'required|trim|xss_clean');
          
$this->form_validation->set_rules('lastName'$this->lang->line('lastName'), 'required|trim|xss_clean');
          
$this->form_validation->set_rules('username'$this->lang->line('username'), 'required|trim|xss_clean|callback_unique_app_scanner_name['.$id.']');
          
$this->form_validation->set_rules('password'$this->lang->line('password'), 'trim');
          
$this->form_validation->set_rules('cPassword'$this->lang->line('repeat_password'), 'trim|matches[password]');

          if(
$this->form_validation->run()){

            
$this->load->model('model_main');

            
$this->model_main->edit_app_scanner($id);

            
            
redirect("main/view_event/".$appScannerResult[0]['EventId']."/#tabs-3");

          }else{
            
redirect("main/edit_app_scanner/".$id);
          }
        }else{
          
redirect("main/view_event/".$appScannerResult[0]['EventId']."/#tabs-3");
        }
      }else{
        
redirect(base_url());
      }
    }else{
      
redirect(base_url()."site/login");
    }
  } 
Reply

#2
your also assuming that $str and $id is true. in the function use $str = false, $id = NULL
validate the variables before executing the query

the form not echoing any messages is because your redirecting
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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