Contact Form 7 Conditional Validation (1 post)

  1. maikunari
    Posted 2 years ago #

    I'm attempting to make fields required based on a checkbox selection.

    In the Contact Form 7 input box I've got neither email nor phone selected as required.

    When the 'email' checkbox is clicked, the email field should become required, then the 'phone' checkbox is clicked it becomes required and the email is not.

    So far the below code resets the title to show the asterisk, and adds the class 'wpcf7-validates-as-required' which is what I believe makes the field subject to validation.

    (email is the first checkbox, I'm only showing the relevant code)

    $(".contact-checkbox input:checkbox:first").change(function() {
        if(this.checked) {
            $('span.email').find('input').prop('title', 'Email*');

    Problem is this doesn't work, the field doesn't validate as required. What am I missing?

Topic Closed

This topic has been closed to new replies.

About this Topic