<![CDATA[ FormIt Filter Out Spam Words spamwords From Message Field - My Forums]]> https://forums.modx.com/thread/?thread=103516 <![CDATA[FormIt Filter Out Spam Words spamwords From Message Field]]> https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556863
I am a designer/developer and my customers get legitimate companies who try and sell them their services though their website's contact forms especially for SEO, website traffic blah blah blah. Well, I figured there had to be a simple solution to check for words in the message field and either give a false confirmation and not submit the form or, as this solution does, simply do nothing which in most cases will meet my need since they'll probably just move on robot or person alike... (again I am sure someone can improve upon this)

So basically I added a few things together and came up with this custom hook which I hope is helpful to someone else as well.

1. I created a snippet called scumwords (so as to not be confused with badwords for eforms I believe it is)
with the php as seen here:
$message = $hook->getValue('message');
 
if (strpos($message, 'website') !== false) {
    return false;
}elseif (strpos($message, 'traffic') !== false) {
    return false;
}else{
    return true;
}

2. Update the words "traffic" and "website" with your words.
3. Added custom hook name "scumwords" into the hooks field, which I put it after spam, like this:
&hooks=`spam,scumwords,email,FormItSaveForm`


And viola! Those emails get ignored with spammers not really sure what is going on and all other emails go through like normal.

What do yall think?! Again, I hope it helps someone else!
]]>
scottpureds Feb 15, 2018, 08:49 PM https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556863
<![CDATA[Re: FormIt Filter Out Spam Words spamwords From Message Field]]> https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556889
I'm not sure how you could modify the message and have your changes make it to the DB. I guess you could save the altered message to a $_SESSION variable and alter FormIt2DB to get it from there.

]]>
BobRay Feb 16, 2018, 05:54 PM https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556889
<![CDATA[Re: FormIt Filter Out Spam Words spamwords From Message Field]]> https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556884
But to also respond to you BobRay, I did consider replacing not just the words but the entire message if those keywords were present, instead of blocking (so they would get a confirmation message and think everything was good) but did not know how. I assume to do that I would need to have a snippet/output modifier for just the message field vs a custom hook? I tried that but got nowhere...

Ideally I would just replace the message field with "I am a spammer." which would be satisfying for me personally and then my customer would just disregard the email. wink

Thanks for the help, I will likely use your snippet vs mine.]]>
scottpureds Feb 16, 2018, 01:46 PM https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556884
<![CDATA[Re: FormIt Filter Out Spam Words spamwords From Message Field]]> https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556874
$hook->addError('fieldname', 'message');


leads to an output in [[!+fi.error.fieldname]]]]>
Jako Feb 16, 2018, 07:31 AM https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556874
<![CDATA[Re: FormIt Filter Out Spam Words spamwords From Message Field]]> https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556873

Your subject line is a little misleading, since you're not really filtering out the bad words, you're preventing posts containing them.

Here's a slightly faster and more generic version that makes it easier to add new words:

$scumwords = array(
    'website' => '',
    'traffic' => '',
);

$message = $hook->getValue('message');

$ok = true;
  
foreach ($scumwords as $key => $value) {

if (strpos($message, $value) !== false) {
    $ok = false;
    break;
}

return $ok;


If you wanted to actually filter out (remove) the words, the code would look like this:

$scumwords = array(
    'website' => '',
    'traffic' => '',
);

$message = $hook->getValue('message');

$message =  str_replace(array_keys($scumwords), array_values($scumwords), $message);
/* Save message to DB here */
return true;




]]>
BobRay Feb 16, 2018, 06:52 AM https://forums.modx.com/thread/103516/formit-filter-out-spam-words-spamwords-from-message-field#dis-post-556873