简体   繁体   中英

Either one of Two required fields in contact form 7 validation while submit in WordPress

I tried this but not getting proper result How to do this with contact form 7

$("input.last4digit").on('change',function(){
   $("input.receipt").removeClass('wpcf7-validates-as-required');
   $("input.receipt").attr({'aria-required':'false', 'aria-invalid':'false'});
}); 

$("input.receipt").on('change',function(){
   $("input.last4digit").removeClass('wpcf7-validates-as-required');
   $("input.last4digit").attr({'aria-required':'false', 'aria-invalid':'false'});
});

I used jQuery to remove class and attributes on change of one field It works on change but after submit button pressed Attributes changes again. and not getting proper result. Any suggestions please....

$('.wpcf7-form').submit(function(){

        var last_4_digit = $('input.last4digit').val();
        var receipt_no = $('input.receipt').val();

        if ( last_4_digit == ''  && receipt_no == '' )
        {
            $('input.last4digit').addClass('not-valid');
            $('.not-valid-tip').text("This or Below field is Required");
            $('.not-valid').focus();
            return false;
        }
        else if( last_4_digit != ''  || receipt_no != '' )
        {
            $('.not-valid-tip').text("");
        }
        else
        {}
    });

After doing this jQuery I got the result as my requirement Its just simple but if you want to go with contact form 7 functionality I am still finding solution for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM