0

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?

1 Answer 1

1

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');
Sign up to request clarification or add additional context in comments.

2 Comments

I don't really want to override PHP's function or use callbacks. Was hoping to be able to do it in CI's validation rules.
well there is no htmlentities rule in CI - so you have no choice. Either override Codeigniter (not PHP), or do a callback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.