CodeIgniter Form Validation – How to get all error fields as an array

CodeIgniter by default is not providing you the error fields for a form as an array. To add this feature to your codeigniter form_valiation library, you have to extend the system library and overload as form_validation library.

Create the file: application/libraries/My_Form_validation.php file and add the following code:

In your controller use the following code to get your error fields as an array:


How to make Yii form fields mandatory manually

When you generate the model and CRUD files, usually all rules in the model is generated automatically and you are not bothered about the rules. But if you want to manually make fields in a form mandatory, you have to write a simple rule in the model rules function – array. Suppose I am having username, email and password in my form and I want all fields to be mandatory. The rules function will be similar to the below code:

Note the last array in the rule, where the first element has all fields (separated by comma) in the form which are required. The second element in the array is the validation class, which is “required” in our case.