Welcome Guest, Not a member yet? Register   Sign In
Validation: Multiple Callbacks on Non-Required Field
#1

[eluser]Simple Gifts[/eluser]
I have a form field that may be blank, but if it isn't blank, it requires several callbacks to review it.

Here's where I set the rule:

$this->form_validation->set_rules('txtSplitCC', 'Split Payments/CC',
'trim|'.
'callback_stripCommas|'.
'callback_verifySplits['.$curTotal.',false]');

Function stripCommas always returns a string, so it never returns false.

The second callback is never called. It appears that if a field is not required, only the first callback is called in the form validation code.

Looking into codeIgniter's system function (version 2.1.3) _execute($row, $rules, $postdata = NULL, $cycles = 0), file Form_Validation.php, it appears that all callbacks are skipped after the first callback inside the rules processing loop:
Code:
// 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;
    }

This is a problem, since I need to work through several callbacks to fully review the input. Any suggestions?

Thanks.




#2

[eluser]noideawhattotypehere[/eluser]
I had a problem using callbacks, but i found solution over the web: make your own library named MY_Form_validation and paste this code
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation{
function run($module = '', $group = ''){
    (is_object($module)) AND $this->CI = &$module;
        return parent::run($group);
}
}

usage:
Code:
$this->form_validation->run($this)




Theme © iAndrew 2016 - Forum software by © MyBB