回调函数错误

时间:2012-09-15 02:33:48

标签: php codeigniter tankauth

好的,我正在创建一个简单的回调函数来检查用户是否插入了禁止的单词。在这里,我到目前为止:(这是使用codeigniter和tankauth)

$this->form_validation->set_rules('firstname', 'First Name', 'trim|alpha|xss_clean|min_length[2]|max_length[50]|callback_is_banned_word');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|alpha|xss_clean|min_length[2]|max_length[50]|callback_is_banned_word');

is_banned_word()函数:

//Check if first or last name is a banned word
function is_banned_word($input) {
    $banned_words = array("word1","word2",...."wordn"); //This is a really long array
    foreach($banned_words as $words) {
        if (stripos($input,$words) !== false) {
            $this->form_validation->set_message('is_banned_word', 'There is a banned word your phrase.');
            return FALSE;
        }
        else {
            return TRUE;
        }
    }
    return TRUE;
}

任何帮助?

1 个答案:

答案 0 :(得分:0)

你的问题是什么?

function is_banned_word($input) {
    $banned_words = array("word1","word2",...."wordn"); //This is a really long array
        if (in_array( $input , $banned_words )) {
            $this->form_validation->set_message('is_banned_word', 'There is a banned word your phrase.');
            return FALSE;
        }
    return TRUE;
}