Minimum Message Length in Fluent Forms
Requires the message field of Fluent Forms to contain at least a few words, so you get enough detail to answer and fewer junk submissions.
Opens WPIDE on
Code
$wpide_ff_words_field = 'message';
$wpide_ff_min_words = 5;
add_filter( 'fluentform/validation_errors', function ( $errors, $data ) use ( $wpide_ff_words_field, $wpide_ff_min_words ) {
if ( ! isset( $data[ $wpide_ff_words_field ] ) || ! is_string( $data[ $wpide_ff_words_field ] ) || '' === trim( $data[ $wpide_ff_words_field ] ) ) {
return $errors;
}
if ( preg_match_all( '/[\p{L}\p{N}\']+/u', wp_strip_all_tags( $data[ $wpide_ff_words_field ] ) ) < $wpide_ff_min_words ) {
$errors[ $wpide_ff_words_field ] = array( sprintf( 'Please write at least %d words so we can help.', $wpide_ff_min_words ) );
}
return $errors;
}, 10, 2 );
Notes
Change the field name and number of words at the top.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.