Skip to content

Instantly share code, notes, and snippets.

@ludekcerny
Last active April 4, 2023 12:27
Show Gist options
  • Save ludekcerny/288f7b89ca37987450154eb6be643637 to your computer and use it in GitHub Desktop.
Save ludekcerny/288f7b89ca37987450154eb6be643637 to your computer and use it in GitHub Desktop.
<?php
/**
* Check if a select field used for selecting differend recipients from the form match the allowed destination domain
* Prevention of spam abuse of the form with publickly visible / manipulable destination address (eg. via browser developer tools)
*/
add_action( 'elementor_pro/forms/validation/select', function( $field, $record, $ajax_handler ) {
$allowed_form_name = "xxx"; // your Elementor form name
$allowed_domain = "example.com";
$field_id = "yyy"; // your select field id , eg. if shortcode is [field id="email-to"], then $field_id = "email-to"
$form_name = $record->get_form_settings( 'form_name' );
//validate only right field and right form
if($field['id'] != $field_id || $allowed_form_name != $form_name){
return;
}
if(!filter_var($field['value'], FILTER_VALIDATE_EMAIL) || substr($field['value'], strlen($allowed_domain)*-1) != $allowed_domain){
$ajax_handler->add_error( $field['id'], 'ERROR: wrong or not allowed email address' );
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment