Cannot get my custom Validation to work

Hi guys,

I've got a custom funciton I want to use for my validation, it's just a basic 'bad word' checker.

So I extended to parent CI_Form_validation class, but I'm getting an error message when I load the form. It was working fine until I extended the class, so I know the problem is there somewhere any help would be great!

My controller function for loading the validation rules:

$this->form_validation->set_rules('title', 'Title', 'required|max_length[100]|alpha_numeric|filterBadWords');

My extension of the CI_Form_validation class (saved under /application/libraries/MY_Form_validation.php):
class MY_Form_validation extends CI_Form_validation {

    function __construct()
    function filterBadWords($string){
        $badWords = array("ban","bad","user","pass","stack","name","html");

        $string = $string;
        $matches = array();
        $matchFound = preg_match_all(
                        "/\b(" . implode($badWords,"|") . ")\b/i",

        if ($matchFound) {
            $this->form_validation->set_message('filterBadWords', 'You are not allowed to use swear words');
            return false;
        } else{
            return true;

And the error message I'm now getting when I navigate to the page with the form is:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: MY_Form_validation::$form_validation

Filename: libraries/MY_Form_validation.php

Line Number: 23

Fatal error: Call to a member function set_message() on a non-object in C:\xampplite\htdocs\\thisone\application\libraries\MY_Form_validation.php on line 23

Any help would be great, thanks guys!!!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.