Set Up Validation

In the function to which your form points, load the validation library and declare your validation rules:

$this->load->library('validation');

$this->validation->set_rules($rules);

Each entry must have something in the 'url' and 'name' fields. CI gives us various options for specifying what that something should be, and the User Guide explains them in full. They're fairly self-evident: min_length[6] obviously means a valid entry in the field must have 6 characters or more, numeric means it must not contain letters, etc. You can also combine rules, using the 'pipe' character to separate them:

$rules['name'] = "required|alpha|max_length[12]";

would require a name of 12 alphabetical characters or less. You can even write your own rules.

Was this article helpful?

0 0

Post a comment