Home / Admin / How to Block Names From Completing Your Form – Simple format
Duplicate Snippet

Embed Snippet on Your Site

How to Block Names From Completing Your Form – Simple format

<10
Code Preview
php
<?php
/**
 * Prevent certain names from the Simple format Name form field.
 *
 * @link https://wpforms.com/developers/how-to-block-names-from-completing-your-form/
 */
function wpf_dev_block_name_validation( $field_id, $field_submit, $form_data ) {
    // Bail early if form ID is not 1000 and field ID is not 10
    if ( absint( $form_data[ 'id' ] ) !== 1000 || absint( $field_id ) !== 10 ) {
        return;
    }
    // Create your list of blocked names separated by commas
    $blocked_names = array( 
        'Jane Doe', 
		'John Doe',
        'Jack Doe'
    );
 
    foreach( $blocked_names as $name ) {
        if(strpos($field_submit, $name) !== FALSE ) {
            wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( 'Can\'t submit form. Please try again later.', 'wpforms' );
            return;
        }
    }
	
}
add_action( 'wpforms_process_validate_name', 'wpf_dev_block_name_validation', 10, 3 );

Comments

Add a Comment