Skip to content

Instantly share code, notes, and snippets.

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