I’m facing a challenge with customizing the Conditional Logic in one of my forms and could really use some assistance. My goal is to allow users to choose their preferred method of contact through radio buttons – either by phone or by email. Based on their selection, I want to make the phone field required if they choose the phone option, but leave it optional if they choose email.
In summary, what I need is
Users select their preferred contact method via radio buttons.
If “Phone” is selected, the phone field becomes a required field.
If “Email” is selected, the phone field remains optional.
I have a basic understanding of how Conditional Logic works in Gravity Forms but my knowledge, especially in PHP, is quite limited. I’ve found a basic script in another thread that adjusts the Conditional Logic requirement based on the value of an input field.
You can create double Email and Phone fields as optional and required and then use conditional logic to display one of them based on the preferred contact method selection.
For a visual guide, please refer to the following screen recording:
You can offer a radio button choice of “Preferred method of contact” with Phone and Email. Make that field required.
Make the Phone and Email fields required.
Use conditional logic on the Phone to show when the radio button choice is Phone, and similarly show the Email field when the radio button is Email.
When the required field is hidden, the form will still be submitted as expected. A hidden field that is required acts like it’s not present in the form. You can test a form on my set that is set up like that:
Yes for sure - this sounds logical - but i only have one fault why this solution isn´t working…
When the phone field is not required it should stay there but as not required. So the sulution with two phone fields, one required and one optional showing as conditional based on the selection is not working because i only can map one phone field for hubspot export feed…
So i think i have to work with a code snippet and not the build in conditional field or do you have another hint for me?
yes for sure - i posted the code in my own first message here. I need help to customize this code to my radio button input to conditional manage the requirement of the phone field… Can you help me to customize?
To explain things more clearly, I have created a screen recording for you. Please watch it below and use the provided code to find a quick solution to your issue. Please note that the code will provide a quick fix but will not form validation. Thank you.
Thank you so much for your fast reply and help! I have added the code and the required marks are workin - howether the real validation is not coming up.
One Question to customize - when phone is marked as communication way the e-mail field should stay required. Could you give me a new Code for showing both fields required for Phone and just e-mail field required for email communication? This would be my final solution…
You’re welcome. I mentioned that it will be frontend validation, not backend. This way, you can have a temporary fix. Here is the updated code for you to try.