Last active
September 27, 2021 09:04
-
-
Save jadealombro/def4b2725843657e439ea03af1f6ce92 to your computer and use it in GitHub Desktop.
Set a minimum word count for inputs to a Single Text Field in WPForms.
This file contains hidden or 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_text', function( $field_id, $field_submit, $form_data ) { | |
// Optional, you can limit to specific forms. Below, we restrict output to | |
// form ID #2056 and field ID #5 | |
if ( absint( $form_data['id'] ) !== 2056 && $field_id !== 5 ) { | |
return; | |
} | |
$min_word_count = 10; | |
if( str_word_count( $field_submit ) < $min_word_count ) { | |
wpforms()->process->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Please enter at least ' .$min_word_count .' words.' , 'wpforms' ); | |
return; | |
} | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment