Validation rules to a config file in CodeIgniter

1

- Advertisement -

You can save sets of rules to a config file. To start, create a new file called form_validation.php, inside the application/config/ directory. The rules must be contained within a variable $config, as with all other config files.
The rules from our Signu form would now appear as follows:

Creating sets of rules
If you have more than one form that needs validating, you can create sets of rules. To do this, you need to place the rules into ‘sub-arrays’. The rules for our contact form would appear as follows when we place it into a set:

This method allows you to have as many sets of rules as you need.
Calling a specific set of rules
You need to specify the rule set that you want to validate the form against, on the run function. Our edited controller would now look like this:

Validation rules to a config file in CodeIgniter (Download script)
Size: V 1
Version: 2.61 MB

- Advertisement -

Leave A Reply

Your email address will not be published.

1 Comment
  1. Igor says

    I’m from Brazil, and your tutorial helped me a lot, thanks for sharing!

Leave A Reply

Your email address will not be published.