Search code examples
phpcodeignitercodeigniter-2

Form Validation required either two fields or a third one


I've searched for a while around the internet and here on StackOverflow. I've found similar needs, but I'm having a hard time adapting those solutions to my specific need.

I'm using CodeIgniter 2, and I've created a form. I'm using form_validation to validate each values entered in the fields.

Now, I have 2 fields which are used for a period of time, and a third field used for a fileID.

The user must either fill [the period of time] fields, or the [fileID] field, or both.

    $this->form_validation->set_rules('idx_start', 'lang:idx_start', 'trim');           
    $this->form_validation->set_rules('idx_end', 'lang:idx_end', 'trim');       
    $this->form_validation->set_rules('fileID', 'lang:fileID', 'trim');

I tried to look into Callbacks and create a custom validation rule but I can't seem to figure out an easy and efficient way for my need.

Thanks in advance for your help.


Solution

  • I've used following Add in to CodeIgniter for my specific need. http://forum.codeigniter.com/thread-22443.html

    Works fine for me. Thanks