Skip to content

Instantly share code, notes, and snippets.

@adczk
Created May 30, 2022 09:05
Show Gist options
  • Select an option

  • Save adczk/30c20df28ec739ccc87ebb98dad20d50 to your computer and use it in GitHub Desktop.

Select an option

Save adczk/30c20df28ec739ccc87ebb98dad20d50 to your computer and use it in GitHub Desktop.
Forminator - disallow use of specific e-mails, block submission
<?php
/************************************
*
* Forminator - disallow some e-mails, issue error
*
* by adamcz/WPMU DEV
* Tested with Forminator 1.15.14
*
* Use as MU plugin
*
* Adjust fields' IDs if needed to match your form
*
*********************************/
add_filter( 'forminator_custom_form_submit_errors', 'check_form_data', 99, 3 );
function check_form_data( $submit_errors, $form_id, $field_data_array ) {
$mail_forms = array( 1445 ); // IDs of forms to check; if more than one, separate by comma
$mail_field = 'email-1';
$error_msg = 'Invalid e-mail address!';
// set disallowed e-mail adresses (may be partial only)
$disallowed = array(
'@gmail.com',
'@yahoo.com'
);
if ( in_array( $form_id, $mail_forms ) ) {
$email = '';
foreach( $field_data_array as $arr ) {
if ( $arr['name'] == $mail_field ) $email = $arr['value'];
}
foreach ( $disallowed as $to_check) {
if ( stristr( $email, $to_check) ) $submit_errors[][$mail_field] = $error_msg;
}
}
return $submit_errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment