Form Validation: "matches" and NOT required |
[eluser]MeXHere[/eluser]
I have two fields, the second must match the first but they are not required because I use them only to update data when the user fills in that data. The problem is that even if the second field is set with the rule "matches" to the first field and the first field is filled in with some data .. the validation passes because the second field is not required ... :gulp: I'm just missing something or it's just not working as expected ?
[eluser]WanWizard[/eluser]
You haven't missed anything. With the current Form Validation implementation it is not possible. A search finds http://ellislab.com/forums/viewthread/110793/
[eluser]CroNiX[/eluser]
A way to get around that is to create dynamic validation rules, or a custom validation rule. For dynamic, when creating your rules, do something like: Code: $first_field = $this->input->post('field_name');
[eluser]n0xie[/eluser]
Doesn't this work? Code: $this->form_validation->set_rules('field1', 'field1', 'matches[field2]');
[eluser]MeXHere[/eluser]
But yes n0xie, It's working in that case; It's only that it says that field1 does not match field2 instead of the way around I suppose I'll be back to using a custom validation rule |
Welcome Guest, Not a member yet? Register Sign In |