# Elementor Forms: Reject Messages Containing Links

> Refuses Elementor Pro form submissions whose text areas contain web links, which stops most contact-form spam without a captcha.

- Type: PHP
- Runs: Run everywhere
- Category: [Page Builders & Themes](https://wpide.com/library/category/page-builders/)
- Tags: elementor, forms, spam
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/elementor-form-block-links/

## Code

```php
// How many links a message may contain.
$wpide_el_max_links    = 0;
$wpide_el_link_message = 'Please remove links from your message.';

add_action( 'elementor_pro/forms/validation', function ( $record, $ajax_handler ) use ( $wpide_el_max_links, $wpide_el_link_message ) {
    $fields = $record->get( 'fields' );

    foreach ( (array) $fields as $id => $field ) {
        if ( ! isset( $field['type'], $field['value'] ) || 'textarea' !== $field['type'] ) {
            continue;
        }

        $links = preg_match_all( '#(https?://|www\.)\S+#i', (string) $field['value'] );

        if ( $links > $wpide_el_max_links ) {
            $ajax_handler->add_error( $id, $wpide_el_link_message );
        }
    }
}, 10, 2 );
```

## Notes

Raise $wpide_el_max_links to 1 if customers often need to paste a single link.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Elementor Forms: Reject Messages Containing Links" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
