2

I am looking for a way to get a WFFM field to be required only if another field has a certain value. If there is a way to make a WFFM field required on the fly through Javascript, that would work fine, but I don't know of a way. Additionally, while the rules engine allows me to select my condition (other field matches value), there is no rule to make the field required.

One of my thoughts was to create a custom rule then, to serve as the action, but the problem I'm running into there is, how would I make a WFFM field required on the fly in C#? Researched online and didn't find anything.

I've found a resource that matched my exact scenario:

  • If contact method selected is Phone, make the Phone field required
  • If contact method selected is Email, make the Email field required

... but I don't understand it. I don't understand which part of the code is actually making the Contact Preference field required. Additionally, the code has some problems and I can't get it to build.

I am using Sitecore 8.0 with WFFM (unknown version).

  • Add version of Sitecore that you use. Can you maybe use similar approach of showing/hiding fields on WFFM form -> stackoverflow.com/questions/7919088/…? For your case you would not show or hide but set requirement of another field. I don't have Sitecore below 9 version installed so I cannot check. If there is no rule like that then create one :) – Peter Procházka Mar 10 '18 at 8:15
  • The link does not apply because there is no Action in the rules editor for my field that allows me to make another field required. Additionally I do not see "Hide element" action. Screenshot: i.imgur.com/0KLTQ9D.png. Can you give more information on how I could create a rule that would make a field required? – Paul Mar 12 '18 at 15:18
  • Also, creating a rule for my requirement means it would be processed server side (once on page load) but I need to make a field required in response to a dropdown selection, so creating a rule would not work.. unless I could make it triggered via Javascript, which I am not sure how to do. – Paul Mar 12 '18 at 15:33
  • How about having two similar fields on the form – Field1 already configured with all the valid mandatory validations but HIDDEN on Page Load and Field2 without any validations & visible. Then write custom JavaScript to show/hide the mandate/non-mandate fields based on the values in your requirements. – Amitabh Vyas Mar 12 '18 at 16:28
1

How about having two fields on the form – Field1 already configured with all the valid mandatory validations but Hidden on Page Load and Field2 without any validations but Visible. Then:

Approach 1:

Write custom JavaScript to show/hide the mandate/non-mandate fields based on the values in your requirements.

Approach 2:

Please have a look at the solution described Sitecore Documentation Portal: Show or hide a form field depending on other field values.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.