Home / Admin / Advanced Spam Filters for Elementor Forms
Duplicate Snippet

Embed Snippet on Your Site

Advanced Spam Filters for Elementor Forms

Filter spam emails by either email provider @gamil.com, @hotmail.com, or whatever you want. You can also stop spam by keywords or phrases found in the form submission. Such as “High quality website“, “do follow links“, “Website DA“.

Spam software can't stop all spam, but we can stop humans who use words and phrases we know we are not interested in.

Code Preview
php
<?php
/** START ELEMENTOR FORM SPAM PROTECTION **/
add_action( 'elementor_pro/forms/validation', function ( $record, $handler ) {
    // Make sure the form is an instance of Form_Record class
    if ( ! $record instanceof \ElementorPro\Modules\Forms\Classes\Form_Record ) {
        return;
    }
    $raw_fields = $record->get('fields');
    $fields = [];
    foreach ( $raw_fields as $id => $field ) {
        $fields[ $id ] = $field['value'];
    }
    // Define blocked domains
    $blocked_domains = ['gmail.com', 'hotmail.com'];
    // Define blocked words/phrases
    $blocked_words = ['High quality website', 'do follow links', 'Website DA']; // Add your words/phrases here
    // Check for blocked domains
    if ( isset( $fields['email'] ) ) {
        $email_domain = substr(strrchr($fields['email'], "@"), 1);
        if ( in_array( $email_domain, $blocked_domains ) ) {
            $handler->add_error( 'email', 'Emails from this domain are not accepted.' );
            return;
        }
    }
    // Check for blocked words/phrases
    foreach ( $fields as $field ) {
        foreach ( $blocked_words as $word ) {
            if ( strpos( strtolower( $field ), strtolower( $word ) ) !== false ) {
                $handler->add_error( 'general', 'Your submission contains blocked words/phrases.' );
                return;
            }
        }
    }
}, 10, 2 );
/** END ELEMENTOR FORM SPAM PROTECTION **/

Comments

Add a Comment