-
-
Save dexit/95af4fe32c09477086c384825ef321eb to your computer and use it in GitHub Desktop.
Elementor Form Validation - Block non-english bots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks form textarea content is english to reduce spam from non-english bots | |
**/ | |
function elementor_form_message_field_validation( $field, $record, $ajax_handler ) { | |
// Let's check the message field only | |
if ( empty( $field ) || empty( $field['message'] ) ) { | |
return; | |
} | |
// Validate content format by language | |
$string = $field['message']; | |
if(strlen($string) != mb_strlen($string, 'utf-8')) | |
{ | |
$ajax_handler->add_error( $field['message'], esc_html__( 'Please enter English words only thank you.', 'elementor' ) ); | |
return; | |
} | |
} | |
add_action( 'elementor_pro/forms/validation/textarea', 'elementor_form_message_field_validation', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment