Created
January 18, 2020 10:46
-
-
Save nastiarocks/24911024cbdf6dadc29bef3986376326 to your computer and use it in GitHub Desktop.
Created by WPMU DEV Developers. Replace the textarea-1 with your ID field. Edit line #6 to set minimum limit of characters
This file contains 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_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){ | |
$field_id = 'textarea-1'; | |
foreach ( $field_data_array as $key => $field ) { | |
if ( $field_id === $field['name'] ) { | |
if ( 15 > strlen( $field['value'] ) ) { | |
$submit_errors[]['textarea-1'] = 'You need to insert at least 15 characters in the textarea'; | |
$_POST['forminator-textarea-invalid-length'] = true; | |
} | |
} | |
} | |
return $submit_errors; | |
}, 20, 3 ); | |
add_filter( 'forminator_custom_form_invalid_form_message', function( $invalid_form_message, $form_id ){ | |
if ( isset( $_POST['forminator-textarea-invalid-length'] ) && $_POST['forminator-textarea-invalid-length'] ) { | |
$invalid_form_message = 'You need to insert at least 15 characters in the textarea'; | |
} | |
return $invalid_form_message; | |
}, 20 ,3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment