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.

Either Field Required

  1. Hi,

    I am looking for the following functionality:

    The user is required to fill in either one of two fields to be able to submit. (e.g. There is a phone number field and an email field and the user must fill in at least 1 to leaves some sort of contact details.)

    Is this possible with Gravity Forms?

    Many thanks!

    Posted 13 years ago on Friday July 8, 2011 | Permalink
  2. This isn't a built in feature. A field is either required or it is not required. There are no options for either or functionality as far as required fields go. It would be possible to do this, but only as a customization using the gform_validation API hook You'd have to write your own custom validation. We have a tutorial on how to use the gform_validation hook here:

    http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_valiation%22_Hook

    Posted 13 years ago on Friday July 8, 2011 | Permalink
  3. I usually handle this with a conditional "How would you like to be contacted?" question, with two multiple choice (radio button) options: phone and email.

    Then you show the phone field if they selected "phone" and the email field if they selected "email" using the built in "conditional logic" feature. Make both the phone and email fields required. Gravity Forms is smart enough to know that a conditional field that is required but unused (i.e. they want to be contacted by phone, so the email field is not used) does not fail validation. It won't be required any longer.

    Here's a quick example:
    http://guitar.chrishajer.com/2011/07/08/conditional-contact-form/

    I'm certain there are other ways to handle it, but this is one simple way. I realize this is a pre-sales question, but rest assured that what you want to achieve is certainly possible with Gravity Forms.

    Posted 13 years ago on Friday July 8, 2011 | Permalink
  4. What Chris said :)

    Posted 13 years ago on Saturday July 9, 2011 | Permalink
  5. I'm also interested in this.
    The example at http://guitar.chrishajer.com/2011/07/08/conditional-contact-form/ is a little bit wonky, though -- if you click Phone and then decide you prefer Email, it won't switch. If you click Email first, then Phone, you get both. Is this default behavior, or would there be a way to clean up the functionality so it would switch if you change your mind on the fly?

    Posted 11 years ago on Wednesday January 30, 2013 | Permalink
  6. The problem with dredging up old posts is that sometimes they no longer work :-)

    I updated my Gravity Forms and WordPress installation there and you will see now that it works.

    Posted 11 years ago on Thursday January 31, 2013 | Permalink
  7. Aha... got it, looks great. Thank you.

    Ethan

    Posted 11 years ago on Thursday January 31, 2013 | Permalink
  8. You're welcome. Good luck to you.

    Posted 11 years ago on Friday February 1, 2013 | Permalink

This topic has been resolved and has been closed to new replies.