Preparing user input

The validation rules can also be used to prepare input for you. For example, you can trim() whitespace from the input or apply htmlspecialchars(). Any PHP function can be used, as long as that function accepts one parameter as an argument by default.

How to do it...

Let's assume that we want to trim() whitespaces from the beginning and end of the input and generate an md5 hash of the input:

$this->form_validation->set_rules('input_name', 'Input Name', 'trim|md5'); 

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.