CodeIgniter Forums
Userdefined Validation Rule - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Userdefined Validation Rule (/showthread.php?tid=48622)



Userdefined Validation Rule - El Forum - 01-23-2012

[eluser]singu[/eluser]
I have two problems to create an userdefined validation rule.

problem 1:
----------
I have two fields. Field 1 or Field 2 must be completed.

problem 2:
I have a dropdown with two values "Company" & "Person". If Company is selected in the dropdown, then field vat must be completed.

CodeIgniter 2.1


Userdefined Validation Rule - El Forum - 01-23-2012

[eluser]Kamarg[/eluser]
There is no question there. What do you need help with? What have you already done? Do you have relevant code to show?


Userdefined Validation Rule - El Forum - 01-23-2012

[eluser]CroNiX[/eluser]
These are pretty easy to do. You can either extend the form validation library with new rules or use callbacks and define the rules in the controller.

For your first one, you would just check to see if $this->input->post('field1') is not empty OR $this->input->post('field2') is not empty.

For the 2nd one, if $this->input->post('dropdown1') has a value, then $this->input->post('dropdown2') must have a value.

There are examples in the user guide on how to create your own callbacks, and also how to extend a CI library. There are also lots of samples in the forums. Beyond that, we would need to see what you have tried so far in order to help more.