title: Custom validation contact form7
body: <p>I need validation of the form - if someone enters a phone number / email then no email / phone number is no longer required. I tried</p>
  
  <pre><code>(function($) {
      $(document).ready(function(){
          $(".wpcf7-email").on('change', function postinput(){
              var id = $(this).val();
              if(id) {
                     document.getElementById('phone').setAttribute("aria-required", "false");
                     $( "#phone" ).removeClass( "wpcf7-validates-as-required" )
             } else {
                     document.getElementById('phone').setAttribute("aria-required", "true");
             }
          });
      }); 
  })(jQuery);
  </code></pre>
  
  <p>And tried PHP</p>
  
  <pre><code>    add_filter( 'wpcf7_validate_text', 'xyz_validation', 20, 2 );
  
      function xyz_validation( $result, $tag ) {
  
          $email = isset( $_POST['email'] ) ? trim( $_POST['email'] ) : '';
          $phone = isset( $_POST['phone'] ) ? trim( $_POST['phone'] ) : '';
  
          if ( !empty($email) &amp;&amp; !empty($subject) ) {
            $result-&gt;invalidate( $tag, "Really?" );
          }
  </code></pre>
  
  <p>My contact form (jquery - in PHP form is not required (no sign '*')</p>
  
  <pre><code>[email* email id:email]
  [number* phone id:phone]
  </code></pre>