Welcome Guest, Not a member yet? Register   Sign In
Form Validation: "matches" and NOT required

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 ...


I'm just missing something or it's just not working as expected ?

You haven't missed anything. With the current Form Validation implementation it is not possible.

A search finds http://ellislab.com/forums/viewthread/110793/

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:
$first_field = $this->input->post('field_name');

    //create your validation rule for 2nd field using matches to first field, and make it required
    //regular validation rules for 2nd field

Doesn't this work?
$this->form_validation->set_rules('field1', 'field1', 'matches[field2]');
$this->form_validation->set_rules('field2', 'field2', 'matches[field1]');

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 Smile
I suppose I'll be back to using a custom validation rule Big Grin

Theme © iAndrew 2016 - Forum software by © MyBB