problem with form_validation : conditional fields validation (one field depends upon another) |
[eluser]t'mo[/eluser]
herringtown, I couldn't do a pure override solution to this, withouth also overriding the core "_execute" method. But, given how useful conditional validation would be if it were in the core, I thought it worth my time to ask them to put it in. (See also http://ellislab.com/forums/viewthread/110793/ .) Hopefully, the requested change could make it into the core distribution.
[eluser]Mike Ryan[/eluser]
Hi, I had the same problem - I hacked the form_validation core to include a depends_on function, which does exactly what you want: Just define it in your validation rules like "numeric|depends_on[other_field]". You do, unfortunately, need to hack at some core files - I'll rewrite this as an extension if there is any interest. I'm kind of hoping something similar will be incorporated into the next version of CI, as I have found it quite a useful rule to have.
[eluser]Unknown[/eluser]
FYI the problem is that the parameter is stripped here in Form_Validation.php line 487 CI v1.7.1: Code: // If the field is blank, but NOT required, no further tests are necessary \w will stop as soon as it hits the [] resulting in just the callback name as a match.
[eluser]Unknown[/eluser]
[quote author="juven14" date="1243156740"]FYI the problem is that the parameter is stripped here in Form_Validation.php line 487 CI v1.7.1: Code: // If the field is blank, but NOT required, no further tests are necessary \w will stop as soon as it hits the [] resulting in just the callback name as a match.[/quote] You can fix this bug in Form_Validation.php library with this code : Code: // If the field is blank, but NOT required, no further tests are necessary
[eluser]jpi[/eluser]
[quote author="cpp643" date="1237252627"]in controller check either of those fields by if($this->input->post('cmb_club')==idofother) { set rules and fields validation for other club input field. } else { set rules and fields validation for club drop down. }[/quote] Set_rules doesn't work (they are ignored) if you use config file for form_validation. |
Welcome Guest, Not a member yet? Register Sign In |