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.
Opens WPIDE on
Code
// 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 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.