Complex Field Validation (without JS)


(Rstone) #1

G'day,

 

Is there a way to perform a server-side validation to check that at least one of a group of questions (textareas) in a custom form have been completed?

 

ie. I have 5 textareas, and I want the user to complete at least one of them (they could answer any amount greater than 1 that they feel comfortable with).

So, none of them are technically 'required', but a minimum of 1 of the 5 questions must be answered, if that makes sense.

 

Perhaps there's some way to chain together Complex Validation Rules/Conditions across each of the questions or something along those lines?

But I'm unsure how to create the logic for this, if it's even plausible.

 

Any suggestions or ideas, gratefully accepted.

 

Cheers.

 

 


(Peter McLeod) #2

Hi
There’s probably an easy way to do it with validation rules, but if not maybe you could separate the question as a new field from the response.


For each text area have a coresponding question the user can select from. So the first text area would correspond to select one, text area two would correspond to select two etc.


Then just make text area one and select one required and the rest can be optional.


The issue would then be validating that each of the selected options in the select fields are unique. But it would depend on what is being asked for each field, as whether this is an issue or not.


Not sure if this helps but if there isn’t a technical solution then a similar process of rethinking the form design might provide a better option.


Thanks

Peter


(Rstone) #3

Hi Peter,

 

Thanks for responding.

I'd like to avoid adding any unnecessary extra fields if possible, and I can't make any single one of the textareas required either.

And I'm bound to the form design by decisions made at higher levels of the organisation.

It's a real conundrum.

 

If anyone has experience with doing something similar using the Complex Validation rules - I'd really appreciate some help.

 

Cheers.


(Rstone) #4

For anyone in the future who is looking for this functionality, I figured out a solution.

 

It turns out Simple Validation Rules can do the job - what I did was:

  • a ) For the first of the fields/textareas, change it to Required, and Save
  • b ) Check the box to add a condition to this validation rule, and Save
  • c ) Click the Change button, and select Use Me on the second field/textarea in the group
  • d ) Choose does not match a regex from the drop-down, and use .+ as the regex (literally a full-stop and a plus without spaces - which just means 1 or more of any character), and Save

Continue this pattern for the rest of the fields/textareas in the group, always selecting the next field to validate on.

When you get to the last field/textarea in the group, in step c) above, wrap the validation around, by selecting the first field to validate on.

 

Now your group of fields will be required if nothing is entered in any of them, but optional if any one (or more) of them contains anything.

Use your %question_error_xxx_qx% keywords in your form bodycopy to display a custom error or add a validation class or however you'd like to alert your user to the issue.

 

I hope this helps someone out.