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.

Make a field required or not, depending on a condition?

  1. webfly
    Member

    I know with "Enable Conditional Logic" I can remove it from the form, but I don't want it removed, I still want it there, just not required.

    Posted 7 years ago on Thursday March 29, 2012 | Permalink
  2. kyle
    Member

    I'm actually searching for this functionality too. I know you can conditionally remove/add a field based on an answer - so you could have two identical fields - one that is required, and one that isn't, and show/hide the field depending on the condition.

    I'm hoping I can find/create a better solution.

    Anyone have a reference to something like this, or a good head start on how to accomplish it using some Javascript and PHP?

    Posted 7 years ago on Tuesday April 3, 2012 | Permalink
  3. kyle
    Member

    Okay, I spent a bit of time on this. It could be prettier, but it worked for my needs.

    I had a number of radio button fields, and some followup questions were only required if the initial question was a specific value. So, a sample Initial question would look like this:

    1. Were you happy with the product you received?*

    - Yes
    - No

    and a follow up question such as:

    2. If you said "No", why was that?

    - Poor quality
    - Have another I like better
    - None of your business!

    So, here's how I solved it. Note, I did not have ajax enabled for these forms, so you'd probably need to do some more to get the fields to be valid using ajax. First some javascript:

    http://pastebin.com/ZfJgrXPx

    and the PHP:

    http://pastebin.com/qhepD4be

    Hopefully that helps someone out. I've commented both files, but let me know if you need more help. If anyone wants to improve upon either script, that'd be great.

    Posted 7 years ago on Wednesday April 4, 2012 | Permalink