Block Fluent Forms Messages Containing Spam Words
Stops Fluent Forms submissions when any text field contains a word or phrase from your block list, such as SEO offers or crypto pitches.
Opens WPIDE on
Code
$wpide_ff_spam_words = array( 'seo services', 'backlinks', 'crypto', 'casino', 'guest post', 'rank your website' );
add_filter( 'fluentform/validation_errors', function ( $errors, $data ) use ( $wpide_ff_spam_words ) {
foreach ( (array) $data as $name => $value ) {
if ( ! is_string( $value ) || 0 === strpos( (string) $name, '_' ) ) {
continue;
}
foreach ( $wpide_ff_spam_words as $word ) {
if ( preg_match( '/\b' . preg_quote( $word, '/' ) . '\b/iu', $value ) ) {
$errors[ $name ] = array( 'Your message contains words we do not accept.' );
return $errors;
}
}
}
return $errors;
}, 10, 2 );
Notes
The error is shown on the first text field that contains a blocked word; matching is case-insensitive on whole words.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.