• Resolved claustraphobia2

    (@claustraphobia2)


    Been searching all over and have not found answer to my question.
    Wondering if I should possibly find another form plugin that will do this. Don’t want to do that as I have always used contact form 7.

    I have a client that would like to hide certain fields and only show up if “YES” is clicked. Is that possible with this form by maybe just adding some code somewhere. Anyone ever do this or accomplish this? If not, any recommendations to a plugin that will already do this?

    Appreciate any responses.

    https://www.ads-software.com/plugins/contact-form-7/

Viewing 5 replies - 1 through 5 (of 5 total)
  • This sort of conditional logic is not available directly in Contact Form 7. It can be done via custom programing but you would need to be rather skilled at WordPress development using PHP and/or jQuery.

    Some of the premium Form plugins do offer some Conditional Logic including Gravity Forms, and Ninja Forms.

    If you know/research a little bit of jQuery this is definitely possible. I spent some time just today working on this. Below is what I coded for my fields to show/hide if certain choices were selected.

    <script>
       $(document).ready(function() {
          //Hides the question initially
          $("#hideQuestion").hide();
    
          //Changes the function if the field is true
          $("question1").change( function() {
             if($("#question1").val() == "Yes"){
                $("#hideQuestion").show();
    }
             else{
                $("hideQuestion").hide();
    }
    });
    });
    </script>

    This is pretty straightforward, but let me know if there is something more direct that you were looking for and I will definitely do what I can to help!

    @golgothus. This is the solution that BunnyBomb provided to us here https://www.ads-software.com/support/topic/plugin-contact-form-7-this-is-how-to-showhide-fields-with-jquery/page/2?replies=2

    But what if I have multiple selection in the dropdown all showing different results? Have someone succeeded in finding the solution? A member came up with this solution:

    if ($("#fault").val() == "Waste Collections" || $("#fault").val() == "Recycling" || $("#fault").val() == "Parking" || $("#fault").val() == "Planning")

    But this isn’t working on my end!

    ANYONE?

    I attempted code similar to that as well when trying to make a comparison, but it didn’t work on my end either and I ended up writing several “if” statements to accomplish what I needed. I plan on taking a look a little more into the “||” comparison value for “if” statements in jQuery to make sure that their values are compared correctly and let you know if I find anything that may help.

    Thread Starter claustraphobia2

    (@claustraphobia2)

    I have used the steps at
    https://www.ads-software.com/support/topic/plugin-contact-form-7-this-is-how-to-showhide-fields-with-jquery/page/2?replies=2

    and worked perfect!!!

    Thanks all for your replies. Much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Possible to hide fields until option is seleted?’ is closed to new replies.