Contact Form 7 Wordpress, checking a few fields, if empty then invalid

Could someone help me to solve the problem. I would like the system work like bellow.

  • If both fields are empty = invalid.
  • If any of the fields is completed = valid
add_filter('wpcf7_validate_text', 'or_input_validation_filter', 20, 2);

function or_input_validation_filter($result, $tag) {

    if ('your-link' == $tag-name) {
        $your_link = isset($_POST['your-link']) ? trim($_POST['your-link']) : '';
        $your_file = isset($_FILES['your-file']) ? trim($_FILES['your-file']['name']) : '';
        
        if($your_link == ''  $your_file == '') {
            $result-invalidate($tag, One of the fields has not been completed?);
        }
    }
    return $result;
}

Topic validation plugin-contact-form-7 php Wordpress

Category Web


I solved my problem

add_filter('wpcf7_validate_text', 'or_input_validation_filter', 20, 2);

function or_input_validation_filter($result, $tag) {

    if ('your-link' == $tag->name) {
        $your_link = isset($_POST['your-link']) ? trim($_POST['your-link']) : '';
        $your_file = (!empty($_FILES["file-image"]["name"])) ? trim($_FILES['file-image']['name']) : '';

        if($your_link == '' && $your_file == '') {
            $result->invalidate($tag, "One of the fields has not been completed?");
        }
           
    }
    return $result;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.