Skip to content

Instantly share code, notes, and snippets.

@jadealombro
Created October 3, 2021 14:36
Show Gist options
  • Save jadealombro/a94746c0a590fc3cd8a70c91a1c0386e to your computer and use it in GitHub Desktop.
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.
<?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