Filtering Subject against an array of words

Hi,
I’m trying to filter what a user input in the subject because I noticed that I’m getting spam emails, so I created an array :

$BannedWords = array('bitcoin', 'crypto','apply now');

Then I have this code:

       if (trim($subject) != '') {
                if (!Validate::isMailSubject($subject)) {
                    $this->errors[] = $this->module->l('Subject is not valid.', 'createticket');
                } elseif (Tools::strlen($subject) > 255) {
				$this->errors[] = $this->module->l('Subject is greater then 255 characters.', 'createticket');
                } elseif (Tools::strpos($subject) == (in_array($BannedWords))) { 
					header('Location: https://google.com');
					exit;
					}
            } else {
                $this->errors[] = $this->module->l('Subject is required field.', 'createticket');
            }

The problem here is that I’m redirected whatever the subject is.

So you already know which condition applies. You can check every condition and the individual parts with var_dump()

var_dump(Tools::strpos($subject) == (in_array($BannedWords)));
var_dump(Tools::strpos($subject));
var_dump((in_array($BannedWords)));

But at least you should get a syntax error, missing arguemnt 2 for in_array. Also i don’t see why you compare that with a string position, or whatever the class does.

What I’m trying to do is to compare any word in subject with what I have in the array if there is a match it will redirect if not it will continue

nothing in your code shows that.

so I’m wrong by using strpos function? what is the correct function then?

Tell me what do you think:

} elseif (in_array($subject, $BannedWords)) {
header(‘Location: https://google.com’);
exit;
}

thank you @chorn for your input, I got it fixed now :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service