CodeIgniter: set_rules for validation, tips/notes

CodeIgniter (CI) has the option to set rules for validation of certain fields. It takes 3 parameters.

The 3 parameters are:

  1. The name of the field on which validation is to be applied
  2. The name used for displaying in the error message
  3. The rules to be applied to the field/object

2 Tips/Notes when using the CI validation:

– When you want to use the set_value() function on a field, but you do not necessarily need it to be validated, for e.g. in the case of a

 <select name='name'> <option>

, you add the field name with 2 blank parameters,

 set_value('name', '', '')

– CI doesn’t allow the first parameter to be in the form of an array, or an array with sub-arrays, e.g.

variable_name[sub_1]

or

variable_name[sub_1][sub_n]

You should rather use:

variable_name_sub_1

or

variable_name_sub_1_sub_n

respectiveley

Leave a Reply