• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a form validation issue

#11
So it seems in 3.1 there was a change to the form validation library that re-orders the rules putting callbacks to be run first.
Quote:Prepare rules
*
* Re-orders the provided rules in order of importance, so that
* they can easily be executed later without weird checks ...
*
* "Callbacks" are given the highest priority (always called),
* followed by 'required' (called if callbacks didn't fail),
* and then every next rule depends on the previous one passing.
*
* @param array $rules
* @return array

I am not sure what the reasoning behind this was but it appears to be fairly annoying. Could just comment out the re-ordering but there must have been a reason this was done.

Perhaps someone from the CI team could tell us why this was. I am going to head over to github to see if I can find a reason behind it, although to me it seems the rules should be applied in the order I put them.

Best wishes,

Paul.
Reply

#12
I can't find it on github. But to revert the order so callbacks are called last, in the form_validation library in the system libraries change line 547:

from:
PHP Code:
return array_merge($callbacks$new_rules); 

to:
PHP Code:
return array_merge($new_rules$callbacks); 

And sanity is returned. However as a disclaimer, I do not know if there are any knock on affects, in that the orders were altered for some reason, and I do not know the reason.

Best wishes,

Paul.

PS LOL I noticed only just now that you mentioned this in your 2nd post, which I must have glibly discarded at that time as I thought I was on 3.1 but was on 3.06.
Quote:I checked the system/libraries/Form_validation.php file(CI 3.1.0), I was wondering is it because of the _prepare_rules function? So, the callback function and rule's order was change.
It says ""Callbacks" are given the highest priority (always called), followed by 'required' (called if callbacks didn't fail), and then every next rule depends on the previous one passing.
So, the "callback" function will be run first, then "required" rule and others?
Reply

#13
Hi Paul

Did you ever get a permanent resolution to this issue? I am new to CI and am also facing this with an application I have migrated from CI 2.1.4 to 3.1.3. I have made the change you suggested to line 547 and all is working ok now but I don't like changing the core files and would like a solution that did not require changing core files. If an extension could be added in the application\libraries folder as an alternative this will not get overwritten by core updates.

Thanks
Philip
Reply

#14
Code:
class MY_Form_validation extends CI_Form_validation
{
    protected function _prepare_rules($rules)
    {
        return $rules;
    }
}
Reply

#15
Hi Narf

Just tested your code, and it worked great for me on 3.1.3. Thanks for your help

Philip
Reply

#16
Hi Guys,

I give thanks to Narf too.

I had the same issue - https://forum.codeigniter.com/thread-67280.html


Mr Lister.
Reply

#17
Paul and Narf, thank you.

You guys help me a lot, and the solution is great.

Thanks again. Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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