I am using CodeIgniter's form validation. Here is an example:
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
The documentation say:
Any native PHP function that accepts one parameter can be used as a rule, like htmlspecialchars, trim, MD5, etc.
What if I want the value to pass through my own custom filter? For example, I would like the value to be cleaned of "badWord".
function curseWordRemove($original = '') {
return str_replace('badWord', '', $original);
}
CodeIgniter already provides ways to do custom validation, but not custom filters. The custom validation only returns true or false, not the filtered string.
function isPolite($string = '') {
if (strpos($string, 'badWord') !== false) {
$this->form_validation->set_message(
'fieldName',
'contains a very bad word'
);
return false;
} else {
return true;
}
}