Stop Words for List fields

Hello, wondering if I could have some advice please. Looking to prevent customers putting in words which aren’t answers. This is important are these are insurance quote forms, so can’t accept ‘unknown’ or just a question-mark symbol. Would the following code under appearance, customise etc be correct:

add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
    GFCommon::log_debug( __METHOD__ . '(): Running...' );
    // Only for List fields.
    if ( $field->type == 'text' || $field->type == 'textarea' ) {
 
        if ( $result['is_valid'] ) {
            $stop_words = array( // List of words to not allow in lowercase.
                'unknown',
                '?',
                'don't know,
            );
 
            // Stop Words Counter.
            $stop_words_detected = 0;
 
            // Check field value for Stop Words.
            foreach ( $stop_words as $stop_word ) {
                if ( strpos( strtolower( $value ), $stop_word ) !== false ) {
                    $stop_words_detected++;
                    GFCommon::log_debug( __METHOD__ . "(): Increased Stop Words counter for field id {$field->id}. Stop Word: {$stop_word}" );
                }
            }
 
            if ( $stop_words_detected > 0 ) {
                GFCommon::log_debug( __METHOD__ . "(): {$stop_words_detected} Stop words detected." );
                $result['is_valid'] = false;
                $result['message']  = 'Sorry, we would need answer, you may wish to save the quote and return once you have the information .';
            }
        }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.