Please read this post and let me know if you think this is something that people would need.
Say I have 3 fields for a user to enter his phone number.
phone_area (555)
phone_pre 123
phone_suff 4567
I want to validate all 3 but only show a single error to the right of the phone_suff field.
For simplicity sake, I’m not worrying about min_length or max_length.
$this->form_validation->set_rules('phone_area', 'Phone Area Code', 'is_numeric');
$this->form_validation->set_rules('phone_pre', 'Phone Prefix', 'is_numeric');
$this->form_validation->set_rules('phone_suff', 'Phone Suffix', 'is_numeric');
If any of you have ever used jQuery’s validation plugin you may know that you can define field groups. This is what I’d like to achieve with CI.
I think something along the lines of
$this->form_validation->set_rules('phone_area', 'Phone Area Code', 'is_numeric');
$this->form_validation->set_rules('phone_pre', 'Phone Prefix', 'is_numeric');
$this->form_validation->set_rules('phone_suff', 'Phone Suffix', 'is_numeric');
$this->form_validation->set_field_group(array('phone_area','phone_pre','phone_suff'), 'phone_suff');
That basically states that any errors that come up for any field within the array are applied to the ‘phone_suff’ field.
So after the form_suff field in my HTML I can have <?php echo form_error(‘phone_suff’); ?> and any errors on all 3 fields show up there.
I realize I can achieve this with a callback but I think this is something that may be useful to some people in the future, and I think it should be fairly easy to implement.
