Validate checkboxes in contact form 7

How to validate the checkboxes to select only one in wordpress contact form 7? I have written the following code in functions.php

function custom_cf7_required_check_filter($result, $tag) {    
    $val = $_POST['Yes']; 
    $opts = strpos($val, ",");

    if($opts != false){
        $result['reason']['Yes'] = "True";
    }else{
        $result['reason']['Yes'] = "False";
    }
    return $result;
}
add_filter('wpcf7_validate_checkbox', 'custom_cf7_required_check_filter', 10, 2);

Related posts

Leave a Reply

1 comment