Created
October 3, 2021 14:36
-
-
Save jadealombro/a94746c0a590fc3cd8a70c91a1c0386e to your computer and use it in GitHub Desktop.
This snippet stops the form from being submitted if the name matches any of the blocked names stored in an array.
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
<?php | |
add_action( 'wpforms_process_validate_name', function( $field_id, $field_submit, $form_data ) { | |
// Bail early if form ID is not 2090 and field ID is not 1 | |
if ( absint( $form_data['id'] ) !== 2090 && $field_id !== 1 ) { | |
return; | |
} | |
$submitted_name = $field_submit['first'] .' ' .$field_submit['last']; | |
// Create your list of names to be blocked separated by commas | |
$blocked_names = array( | |
'Eric Eric', | |
'Lucia Lucia', | |
'Johan Johan' | |
); | |
foreach( $blocked_names as $name ) { | |
if( strcmp( $submitted_name, $name ) == 0 ) { | |
wpforms()->process->errors[ $form_data['id'] ]['header'] = esc_html__( 'Can\'t submit form. Please try again later.', 'wpforms' ); | |
return; | |
} | |
} | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment