dallen
dallen

Reputation: 2651

Validating array of fields, allow passing if at least one is filled in

My validation is setup like so:

[
    'field' => 'impressions[]',
    'label' => 'Impressions',
    'rules' => 'required'
],

I have five of these input fields called impressions[]. The problem I'm having is that unless all are filled in, the form won't validate. I want to make it so that only one is required. Any best practices for this?

Upvotes: 0

Views: 87

Answers (1)

jmadsen
jmadsen

Reputation: 3675

@dallen,

You'll want to use a validation callback to check that:

http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks

You can pass the impressions to it, then do normal php array size checking, etc

Upvotes: 2

Related Questions