StackOverflowNewbie
StackOverflowNewbie

Reputation: 40633

CodeIgniter Validation: using PHP functions

I'd like to use htmlentities as part of my CI validation/prepping process. CI says I can use any function that accepts 1 parameter, like htmlentities. However, I actually need to use it this way:

htmlentities($foo, ENT_COMPAT, 'UTF-8');

Meaning, I need to pass it flags and an encoding. Is there a way I can make this part of CI validation without trying to create a callback?

Upvotes: 0

Views: 148

Answers (1)

Laurence
Laurence

Reputation: 60038

If you extend the form_validation class, and add this as a function - then you can use it globally on all your validations.

public function htmlentities($str)
{       
       return htmlentities($str, ENT_COMPAT, 'UTF-8');
}

And then use it like this

$this->form_validation->set_rules('text', 'Text', 'required|htmlentities');

Upvotes: 1

Related Questions