Welcome Guest, Not a member yet? Register   Sign In
Validation Callback
#1

[eluser]jleequeen[/eluser]
Hello,

I'm having trouble getting a callback validation function to work. I've never used a callback before so I don't know if i'm doing it right. Below is the code. In the callback function I have set it up so that it will automatically trip the validation to false just to get it working. The callback is getting totally ignored. The validation on each of the other rules works fine, so I know it's got something to do with the callback function. Any ideas?

Code:
function distribution() {

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

     $rules['total_miles'] = 'trim|required|numeric';
     $rules['feet_replaced'] = 'trim|required|numeric';
     $rules['feet_added'] = 'trim|required|numeric';
     $rules['meters_replaced'] = 'trim|required|numeric';
     $rules['percent_check'] = 'callback_percent_check';

     $this->validation->set_rules($rules);

     if ($this->validation->run() == FALSE) {
          $this->load->view('distribution');
     } else {
          //save some stuff to the model
          redirect('somewhere');
     }
}

function percent_check() {
     $total = 20;
     if ($total == 100) {
         return TRUE;
     } else {
         $this->validation->set_message('percent_check', 'Estimated percentage of lines should equal 100%.');
         return FALSE;
     }
}


Messages In This Thread
Validation Callback - by El Forum - 08-12-2008, 02:22 PM
Validation Callback - by El Forum - 08-12-2008, 03:00 PM
Validation Callback - by El Forum - 08-12-2008, 03:03 PM
Validation Callback - by El Forum - 08-12-2008, 03:07 PM
Validation Callback - by El Forum - 08-12-2008, 03:09 PM
Validation Callback - by El Forum - 08-12-2008, 03:17 PM
Validation Callback - by El Forum - 08-12-2008, 03:18 PM
Validation Callback - by El Forum - 08-12-2008, 03:24 PM
Validation Callback - by El Forum - 08-12-2008, 03:32 PM
Validation Callback - by El Forum - 08-12-2008, 04:00 PM
Validation Callback - by El Forum - 08-12-2008, 04:06 PM
Validation Callback - by El Forum - 08-12-2008, 04:10 PM
Validation Callback - by El Forum - 08-15-2008, 06:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB