• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation callback not called...

#1
[eluser]dynZack[/eluser]
For some reason a validation callback is never called. Here's the code:



Code:
function process_form(){
        
        //check if categories are set
        $this->form_validation->set_rules('categoryParent', 'categoryParent', 'required|callback_notdefault');
        if ($this->form_validation->run() == FALSE){//validate
           echo validation_errors();
           return;
        }
}

Code:
function notdefault($str){
        // die($str)   <-- never reached
        if( ($str === '0') ){
            $this->form_validation->set_message('not_default',
$this->lang->line('choose_category_subcategory'));
             return FALSE;
          }    
          else {
             return TRUE;
            
          }
    }

I'm banging my head against the wall for the last 3+ hours and I'm having thoughts of cutting my dick off. :ahhh:

Can anyone spot what might be the problem?


Edit: Corrected the name of the callback function

#2
[eluser]kaos78414[/eluser]
Change this line:
Code:
$this->form_validation->set_rules('categoryParent', 'categoryParent', 'required|callback_notdefault')

to this

Code:
$this->form_validation->set_rules('categoryParent', 'categoryParent', 'required|callback__notdefault')

#3
[eluser]dynZack[/eluser]
That was my mistake, I was trying other names and forgot to change it back. So unfortunately that's not the problem.

Everything looks ok: Callback is in the same controller, can be reached at http://www.exampe.com/controller/notdefault/a_string

don't know what else to think

#4
[eluser]dynZack[/eluser]
It looks like notdefault method is not found by the Form_validation library

Line 581 added die() if callback method not found

Code:
// Call the function that corresponds to the rule
            if ($callback === TRUE)
            {
                if ( ! method_exists($this->CI, $rule))
                {        
                    die ($rule); // <<--- outputs notdefault
                    continue;
                }
                
                // Run the function and grab the result
                $result = $this->CI->$rule($postdata, $param);

                // Re-assign the result to the master data array
                if ($_in_array == TRUE)
                {
                    $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
                }
                else
                {
                    $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
                }
            
                // If the field isn't required and we just processed a callback we'll move on...
                if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE)
                {
                    continue;
                }
            }

#5
[eluser]dynZack[/eluser]
Spot the problem: HMVC

Solution here


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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