Created
March 6, 2024 17:20
-
-
Save pingram3541/7839cdd44a485cbc8b619e5e21e6170e to your computer and use it in GitHub Desktop.
Elementor Form Validation - Block non-english bots
This file contains 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