PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Conditional statement in form depending on field answer

  1. RichardBest

    Hi there - I'm thinking of using Gravity Forms for a completed set-of-forms set-up. To make it work, I need to be able to implement this scenario:

    A person is filling in a form. One or more fields in the form need to be answered in a certain way for it to make any sense to continue with the form. For example, let's say there's an A, B or C multichoice field. It only makes sense to continue if the user answers A. I can use conditional logic to hide all subsequent questions if the user doesn't answer A (i.e, if s/he answers B or C), but I'd like a warning box to appear when the user answers B or C. Ideally a red extension to the current field would show, which would contain customised wording I set, basically informing the user that she cannot continue unless she answers in a certain way. This is not the same as setting a field to "Required status". It's more refined than that. The user needs to be able to answer in different ways (as opposed to answer or not answering at all) but I need the option for a warning to appear if s/he answers B or C (in this example).

    Is this sort of thing possible with Gravity Forms? Or will it only be possible when you add the forthcoming text option (which presumably will enable one to let that text appear by reference to conditional logic)?

    Many thanks

    Posted 11 years ago on Saturday June 12, 2010 | Permalink
  2. It may be possible to do this using jQuery. Attach an action to a specific field so that if it is selected the jQuery could fire a javascript alert box/warning. There isn't any built in functionality to do this so it would have to be via custom jQuery code that interacts with the form.

    When we add a free form HTML box/field it would be possible to show/hide this field based on a selection and you could display some sort of message that way. But this won't be introduced until v1.4 at the earliest.

    Posted 11 years ago on Sunday June 13, 2010 | Permalink
  3. RichardBest

    Thanks Carl. I'm afraid the jQuery code you mention is beyond me. I understand entirely if this isn't a runner, but is there any chance one of the team could post some sample code to show how this would work in practice please?

    Thanks in advance for any help you can provide.


    Posted 11 years ago on Monday June 14, 2010 | Permalink
  4. Hi Richard,

    To clarify, are you only interested in having text appear if a non-proceeding answer is selected? Also, if a non-proceeding answer is selected should the other fields on the form be inaccessible/grayed out/hidden completely?

    Posted 11 years ago on Monday June 14, 2010 | Permalink
  5. RichardBest

    Hi Spivurno

    Yes, I think it is only when a non-proceeding answer is selected that I want the warning text to appear. As regards your second question, I think I could use GF's existing conditional logic to hide the remaining fields (or sections of fields) on the form when a person selects a non-proceeding answer within a field.

    Perhaps I should also clarify that I'm hoping to have multiple non-proceeding answers, across different fields, within the single form. So the single form might be quite complex, with up to 20 or 30 questions. Along the way, there'd be a handful of non-proceeding answers for some answers to some of the fields.

    Come to think of it, it would also be excellent if I could disable the submit button when a person selects a non-proceeding answer.

    I hope this makes sense.

    Thanks in advance if you're able to provide some help on this. Much appreciated.


    Posted 11 years ago on Tuesday June 15, 2010 | Permalink
  6. Hi Richard,

    I believe this might do the trick for you:

    To create a similar effect, you can use the following code as a base:

    That little bit of code would read something along the lines of: Whenever the value of this specified field changes, check if the new selected value is equal to this specified value. If it is, let's display an error message. If not, let's remove any error messages that might be showing.

    There is probably more optimal way given that you are going to having many questions and each would require it's own block of code like the one provide with the field id and specified value updated for each, but this will at least get you started.

    Hope this helps!

    Posted 11 years ago on Wednesday June 16, 2010 | Permalink
  7. RichardBest

    That's superb. Thanks so much. Very much appreciated David.

    If I could just clarify a couple of points please:

    (1) does the code go in the functions.php file?
    (2) does "input 3_3" mean form 3 field 3 (excuse the ignorance, I should know this one...)

    Many thanks. Superb.


    Posted 11 years ago on Wednesday June 16, 2010 | Permalink
  8. Hi Richard,

    (1) This would ideally go in an external javascript file. If you view the source the demo page you'll see that I include an external js file called "init.js":

    <script type='text/javascript' src=''></script>

    I try to put any code that should be run after the DOM is ready in that file. Just helps to keep things organized.

    (2) Pretty much. Specifically, it is the ID of the field you would like to target. This ID is automatically generated by Gravity Forms based on the logic you deducted: "input_3_3" is form 3 field 3. The best way to get the ID of the field you want to target is to just view the source on the form you are working with and find the field and corresponding ID that way.

    Glad this is going to work for you. :)

    Posted 11 years ago on Wednesday June 16, 2010 | Permalink
  9. RichardBest

    Hi again - I'm now trying this but am having trouble getting the javascript file (init.js) into the right place. I've called the script in my header.php but doubt that's the right place for it. Can someone help please?

    Many thanks

    Posted 11 years ago on Saturday June 19, 2010 | Permalink