How to Implement custom validation in multiselect list in contact form 7 wordpress?
add_filter( 'wpcf7_validate_select', 'custom_select_validation_filter', 20, 2 );
function custom_select_validation_filter( $result, $tag ) {
if ( 'classtype-1' == $tag->name ) {
if($_POST['menu-123'] =='Nursery to III'){
$selected_options = isset( $_POST['classtype-1'] ) ? $_POST['classtype-1'] : '';
if(count($selected_options) < 2){
$result->invalidate( $tag, "Select Atleast 2 options." );
}
}
}
if ( 'classtype-2' == $tag->name ) {
if($_POST['menu-123'] =='IV to VIII'){
$selected_options = isset( $_POST['classtype-2'] ) ? $_POST['classtype-2'] : '';
if(count($selected_options) < 2){
$result->invalidate( $tag, "Select Atleast 2 options." );
}
}
}
return $result;
}