Validate checkboxes with CF7
-
How? Validate checkboxes with CF7
I have this code
function cf7_length_validation_filter( $result, $tag ) { $name = $tag['name']; $value = isset( $_POST[$name] ) ? trim( $_POST[$name] ) : ''; $minLen = 0; // Empty Fields if( empty( $value ) || strlen( $value ) == 0 ) { $result->invalidate( $tag, "Field cannot be empty." ); } // Field Length switch ( $name ) { case 'fname': case 'lname': $minLen = 2; break; case 'email': $minLen = 6; break; } if ( empty( $value ) || strlen( $value ) < $minLen ) { $result->invalidate( $tag, "This field is too short." ); } return $result; }
It works for those fields. For checkbox, it ALWAYS says Field cannot be empty
add_filter( ‘wpcf7_validate_checkbox*’, ‘cf7_length_validation_filter’, 5, 2 );
without this line, no validation happens at all
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Validate checkboxes with CF7’ is closed to new replies.