Welcome Guest, Not a member yet? Register   Sign In
form_validation - run($ruleset) doesn't take precedence?

Disclaimer : I am sorry if my use of terms isn't correct. I hope what I mean can be discerned through context. I'm still pretty fresh-faced when it comes to PHP/CI/etc.

I'm running the form validation on a form in which it is necessary to perform cascading validations, like

Initial validation
   If (CASE)
       Secondary Validation
   If (Another CASE)
       Tertiary Validation
and etc.

I discovered something... odd and I'm not sure if it's oversight or intended behavior.

I'm taking advantage of the Form_validation configuration functionality (because it's awesome) and I have several "rule" sets within that file.

When testing validation on my form, I have discovered that the initial validation worked, but the secondary (and likely by extension tertiary) validations were basically being skipped.

On digging a little deeper, I discovered this line of code within the Form_validation library :

if (count($this->_field_data) === 0){

When I read the rest of the run(...) function, it became clear to me that the _field_data variable is set when run is called with a proper rule set... but that's it. If run is called again in the same post, then the old rule set is still in force, even if it's called with a new rule set.

So I'm thinking it might be better to force run() to assign a new rule set each time it's called (which may result in some more overhead) if run is called with a ruleset (instead of being called empty).

So... Is there a reason that this is not the case? (Again, I'm pretty new to this, so it could be something pretty "Duh" to everyone else).

I would like to help but I can't understand why you would run validation like that. You only have one set of posted data, so surely one set of validations to do?

You can nest your validation statements:

Initial validation - but just set the rules
Secondary Validation - just setting the rules
If (Another CASE)
Tertiary Validation - just setting the rules
Run validation

If your "(CASE)" is something like, did this particular field get set or not, you can just do an isset on the $_post, or $this->input->post() will return null, which you can test for as well, in setting your validation rules up.

Alternatively you can run additional validations on any array: http://www.codeigniter.com/user_guide/li...-than-post

If you post a more concrete example I may be able to be a bit more helpful.

Hope that helps,


Did you try reset_validation()?

Theme © iAndrew 2016 - Forum software by © MyBB