Validating the form
For example, if you need to run a database query to see if the user is choosing a unique username, you can create a callback method that does that. In your controller, change the “username” rule to this: Reload your form and submit it with the word “test” as the username.
You can see that the form field data was passed to your callback method for you to process.
Code Igniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data at the same time.
To set validation rules you will use the Before moving on it should be noted that the rule setting method can be passed an array if you prefer to set all your rules in one action.
Although there is nothing terribly complex about the above process, it usually requires a significant amount of code, and to display error messages, various control structures are usually placed within the form HTML.
Form validation, while simple to create, is generally very messy and tedious to implement.
To store your validation rules, simply create a file named form_in your application/config/ folder.
In the above example, we are “trimming” the fields, checking for length where necessary and making sure that both password fields match.
The one you will use most commonly is: The validation system supports callbacks to your own validation methods.
This permits you to extend the validation class to meet your needs.
If you submit the form you should simply see the form reload.
That’s because you haven’t set up any validation rules yet.
You can also use an anonymous function: Of course, since a Callable rule by itself is not a string, it isn’t a rule name either.