• Is there any way I can make a field appear only if the person selects the YES radio button and make it required?

    Example:

    Are you a student?

    Yes No

    If Yes, What are you studying?

    Currently If I make both questions required and someone chooses yes,
    They are required to fill out the second field which is not-applicaple so the form can’t be submitted.

    If I only make the first question required, Someone can select Yes for the first question but leave the second one empty and the form still can be submitted.

    Any idea or any other suggestion that would help me achieve this?
    A conditional logic would work.

    Thanks

    https://www.ads-software.com/plugins/participants-database/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author xnau webdesign

    (@xnau)

    This has to be done using javascript, not terribly difficult if you are familiar with jQuery. You can put your script into a custom plugin template.

    Thread Starter phoenixobia

    (@phoenixobia)

    I am not very familiar with jQuery but I can certainly understand and follow instructions on how to work with jQuery and javascript. Do you have any instructions or any other link to a solution that someone else has done for your plugin?
    Hope you consider this for an update because this plugin is very good.

    Please let me know how you can help me with this.

    Thank you!

    Plugin Author xnau webdesign

    (@xnau)

    I suggest you do a web search for something like: “jquery conditional hide form input” you’ll find lots of examples of how to do this. That’s what I would do.

    Take a look at this article that explains how to use custom plugin templates:

    How to Create Custom Templates

    Thread Starter phoenixobia

    (@phoenixobia)

    Thanks for the info.
    I have tried a few solutions but none seems to work. Not sure what I am doing wrong.

    I added jQuery files to my root in a folder and then added the following code to my head:

    <script src=”/jq/jquery-1.11.2.js”></script>
    <script src=”/jq/jquery-1.11.2.min.js”></script>
    <script>
    $(‘input[name=”subscribe”]’).on(‘click’, function(){
    if ( $(this).is(‘:checked’) ) {
    $(‘input[name=”email”]’).show();
    }
    else {
    $(‘input[name=”email”]’).hide();
    }
    });
    </script>

    I also tried adding it on top of pdb-signup-default.php and copied it in my child theme’s template folder.
    Still no luck.

    Any idea?

    Thanks

    Plugin Author xnau webdesign

    (@xnau)

    I don’t know, but to start with, you can’t use “$” as an alias for jQuery in the WordPress environment. either replace the “$” with jQuery” or use no-conflict mode.

    Try it in Firefox, use the developer tools, they will help a lot.

    I used the following code successfully on the page template inside my child theme. The form has a field inquiring “Do you have a guest?” with the radio button for Yes. (I left off No, as the rest of the form was irrelevant if there was no guest.) If the field “guests” is checked the hidden fields are shown.

    As the pdb form is a table, the code below targets specific parts of the table using the :nth-child() selector. You’ll need to figure out which table rows you want to hide and insert the correct numbers in the :nth-child() selectors, and the replace the field guests with whatever your field is called.

    Hope this helps.

    /*IN CHILD THEME HEADER.PHP*/

    <script src="<?php echo get_template_directory_uri(); ?>/jq/jquery-1.11.2.js" type="text/javascript"></script>
    <script src="<?php echo get_template_directory_uri(); ?>/jq/jquery-1.11.2.min.js" type="text/javascript"></script>

    /*ON PAGE TEMPLATE*/

    <script type="text/javascript">
    	jQuery(document).ready(function($) {
    	$(".form-table tr:nth-child(4),.form-table tr:nth-child(5),.form-table tr:nth-child(6)").hide();
    	$("input[name=guests]").click(function()
    		{
    		if ( $("[name=guests]").attr('checked'))
    			$(".form-table tr:nth-child(4),.form-table tr:nth-child(5),.form-table tr:nth-child(6)").show();
    		});
    	});
    </script>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Make a field appear based on a previous seclection’ is closed to new replies.