Welcome Guest, Not a member yet? Register   Sign In
form validation: double custom function callback
#1

[eluser]Unknown[/eluser]
Hello,
I'm tring to validate a field using 2 custom functions callback, my code look like this:
Code:
function _set_rules(){
...
$rules['close_time_d'] = 'trim|callback_valid_date|callback_valid_date_after';
...
$this->validation->set_rules($rules);
...
}

Then, of course i defined valid_date and valid_date_after functions.

Only the first validation (valid_date) is performed, this sounds me strange. I checked validation library code and I found in run() function this:

Code:
// If the field isn't required and we just processed a callback we'll move on...
if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE)
{
  continue 2;
}

It sounds like if the field is not required, only the first callback function is processed... why? Is this a bug or someone could explain it to me?
For test I removed this lines from validation library and everything worked good.

Thank you.
G.
#2

[eluser]WanWizard[/eluser]
Which version of CI do you use? Mine has
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;
                }
so it must have been a bug that was fixed at some point...
#3

[eluser]danmontgomery[/eluser]
The validation library is deprecated. Use form_validation, which is what WanWizard is looking at.
#4

[eluser]WanWizard[/eluser]
Ah, oops, missed that. Title of this thread threw me off.

Well spotted, @noctrum!
#5

[eluser]Unknown[/eluser]
Thanks guys, I was using some old sample code, I will use form_validation!

G.
#6

[eluser]Unknown[/eluser]
Hi All,
I'm new to CI (v1.7.2) too: is it possible to help newbies using deprecated methods/libraries - maybe thanks to the very first quick help of some snippets Wink - to stay away from deprecated stuff e.g. using something like:
Code:
// Function: as the very first line of code in a function
trigger_error("Deprecated function called", E_USER_NOTICE);
// ||
// Class: as the very first line of code in a class constructor
trigger_error('Deprecated! Use <class name> instead', E_USER_NOTICE);
?
[LOW PRIORITY]

TIA,
Matteo




Theme © iAndrew 2016 - Forum software by © MyBB