WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] This is how to show/hide fields with jQuery (44 posts)

  1. jdavhar
    Member
    Posted 1 year ago #

    BunnyBomb

    saved me hours

  2. 39images
    Member
    Posted 1 year ago #

    BunnyBomb/Anyone,

    Is there any way to use conditional fields with CF7 to run a payment through Authorize.net?

    For example, we have a form created in CF7 whereby a person can register their team for a baseball showcase. I would like to add something in our form that says "Would you like to pay now?"

    If they click "No" they submit the form as usual. If they click "Yes" it populates the Authorize.net fields (Name, credit card number, etc...) for them to fill out before they can submit. We're using the CF7 to database plugin as well to track all of our submissions, so we'd also like to be able to see who paid and who didn't pay.

    In thinking about this, it almost seems too complex because if they click "Yes," their credit card info will have to go through Authorize.net while the rest of the form data comes to us.

    Is this at all possible??

    Thanks! :)

  3. fcvolunteer
    Member
    Posted 1 year ago #

    @jinumanalody how were you able to assign id tags to each radio button option? I looked at the example you posted and it works perfectly. Mine isn't working and I think it's because I can't differentiate between the different options with unique id tags. Really would love to get this working with radio buttons and checkboxes.

    thanks!

  4. Bos
    Member
    Posted 1 year ago #

    Second hiding doesnot show up?
    The first hidefunction operates perfect, I added e second hide function (and i am intending to create more hidefunctions). But the field doesnot show up?
    See the jQuery code and the contactform code here below. What i am doing wrong?

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    /*! jQuery script to hide certain form fields */
    $(document).ready(function() {
    	//Hide the field initially
    	$("#hide1").hide();
      $("#hide2").hide();
    	$("#hide3").hide();
    	//First hidefunction: Laat de tekst zien, waneer resp "ik kom niet", "mijn partner komt niet" gekozen wordt.
    	$('#wieniet').change(function() {
    		if ($("#wieniet").val() == "ik kom niet") {
    			$("#hide1").show();
    		}
    		else {
    			$("#hide1").hide();
    			}
    			if ($("#wieniet").val() == "mijn partner komt niet") {
    			$("#hide2").show();
    		}
    		else {
    			$("#hide2").hide();
    			}
    	});
    //Second hidefunction:Laat de tekst zien, waneer resp "graag informatie over mogelijke invaller", "ik zorg zelf voor een invaller" gekozen wordt.
    	$('#intinv').change(function() {
    		if ($("#intinv").val() == "ja") {
    			$("#hide3").show();
    		}
    		else {
    			$("#hide3").hide();
    			}
      });
    });
    
    Contact Form 7 code:
    <table>
    <tr>
    
    <td><label for="wieniet">Wie komt er niet?*</label></td>
    <td>[select* wieniet 20 id:wieniet include_blank class:contactForm "ik kom niet" "mijn partner komt niet" "mijn partner en ik komen niet"]</td>
    <tr>
    <td><div class="hide" id="hide1">
            <label for="telp">Telefoonnr. partner*</label>
            [text* telp 11/11 id:telp class:contactForm]
    
     <label for="intinv">Interesse om met invaller te spelen?*</label>
    [select* intinv include_blank "ja" "nee"]
    </div>
    
    <div class="hide" id="hide2">
              <label for="mtel">Mijn telefoonnr.*</label>
              [text* mtel 11/11 id:mtel class:contactForm]
      <label for="intinv">Interesse om met invaller te spelen?*</label>
    [select* intinv include_blank "ja" "nee"]
    </div>
    
    </tr>
    <tr>
    <td>
    <div class="hide" id="hide3">
    
      <label for="zinv">Indien er interesse is om met een invaller te spelen:*</label>
    [select* zinv  id:intinv include_blank class:contactForm "graag informatie over mogelijke invaller" "ik zorg zelf voor een invaller"]
    </div>
    </td>
    </table>
  5. @HermanBos Please post your own topic. This one is resolved and those tend to get ignored.

    http://wordpress.org/support/plugin/contact-form-7#postform

  6. Allen Tullett
    Member
    Posted 1 year ago #

    Is it possible to include multiple variables in the if statement within the jquery?
    What I would like to do is allow someone to select any one of several items in a drop down list in order to display the hidden fields.

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

    Is this possible and what am I doing wrong.
    I'm new to jquery and hope its something simple. I appreciate any help you can provide.
    Thanks,
    Allen

  7. Allen Tullett
    Member
    Posted 1 year ago #

    Its okay, I figure it (good old stackoverflow)

    I repeat the element in the brackets divided by ||

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

  8. digitalrenewal
    Member
    Posted 1 year ago #

    has anyone gone all the way through this process? It makes an awesome looking form, but messy output to your inbox. Does anyone know how to hide the empty fields in the 'message body' as well???

  9. @digitalrenewal as this thread has been resolved already can you please start your own new one? You'll get a more targeted response if you do.

    http://wordpress.org/support/plugin/contact-form-7#postform

  10. Bos
    Member
    Posted 1 year ago #

    Nobody did help me, so after a long time of trial and error I solved this problem myself.
    Every hiding that has to fullfill to the same condition you have to write an if/else statement more with another hide number.
    Every other hide condition you have to write a new JQuery script. See step 3 of the work of BunnyBomb.
    You have to give this script another filename. For instance hidefieldsScript2.js.
    Ad this file directly into the "js" folder for your theme (example: "./wordpress/wp-content/themes/your-theme-name/js/".
    Don't forget step 5 by adding "<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/js/hidefieldsScript2.js"></script> to the header.php
    Now you are able to expand the contact form with extra hidings and new conditions for hiding.
    It works great!

  11. Edgar
    Member
    Posted 1 year ago #

    Wow! thanks for this tutorial. I've been searching on this feature for so long until I landed to this thread through searching in Google. It really works for me, I even created more if else statements for more hide and show up fields.

    Many thanks BunnyBomb!!

  12. Michael Shinosky
    Member
    Posted 1 year ago #

    I can't get this to work at all in the Genesis Framework with a child theme. What I noticed in the Genesis framework is the jquery version is 1.7.2 and not 1.7.1 like Bunny's tut. I don't know if this has anything to do with the code not functioning properly or not. I wouldn't think so - but I can't figure it out. Anyone find the same problem? Also - working with the latest CF7 Version 3.3.1 and latest WP Version 3.4.2

  13. jetonr
    Member
    Posted 1 year ago #

    I needed the same option HermanBos mentioned where you need to hide the required field and I came up with this trick which works in IE Chrome Firefox test others and let me know!

    <script type="text/javascript">
    /*! jQuery script to hide certain form fields */
    $(document).ready(function () {
    
        //Hide the field initially
        $("#hide").hide();
    
        //Show the text field only when the third option is chosen
        $('#dropdown').change(function () {
            if ($("#dropdown").val() == "Other") {
                $("#hide").show();
                var input = $("#hide");
                if (input.length > 0) { //If the input field contains any value remove it
                    input.val('');
                }
    
            } else {
                $("#hide").hide();
                var input = $("#hide");
                input.val("NA"); //add NA Value to hidden field that is required!
    
            }
        });
    });
    </script>
  14. venkmanuk
    Member
    Posted 1 year ago #

    Thanks Bunnybomb !!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic