Nested OR operator
-
Is there a way to have ‘OR’ operator inside a condition like
show [prix9] if [compagnie] equals “Air France Tahiti” or ‘Air Antilles”
and if [fonction] equals “Hôtesse-Steward / Cabin Crew”
-
No, but this will have the same effect:
show [prix9] if [compagnie] equals "Air France Tahiti" and if [fonction] equals "Hôtesse-Steward / Cabin Crew" show [prix9] if [compagnie] equals "Air Antilles" and if [fonction] equals "Hôtesse-Steward / Cabin Crew"If AND is not used, OR is implied.
I see that in your case this leads to some redundancy. One way you could solve this to use nested groups:
[group fonction-cabin-group] [group prix9][/group] [/group]This way you can Just write this:
show [prix9] if [compagnie] equals "Air France Tahiti" show [prix9] if [compagnie] equals "Air Antilles" show [fonction-cabin-group] if [fonction] equals "Hôtesse-Steward / Cabin Crew"ok, so it’s not possible. This was just one part of my code and in my form I need to use many conditions and as pointed I want to avoid redundancy. I dealt by repeating each options and thanks to the text editor I could may that quickly. What would be a great enhancement would be the ability to create such a logic:
if condition 1 equals "a" or "b" and condition 2 equals "1" or "2" then field-x is shown
Could you add this to your plugin? I’m used to the extraordinary webform on Drupal and I dream of such power in Contact form7 🙂Can you set up a small version of your form so I can understand the logic better? You can set up the form via https://conditional-fields-cf7.bdwm.be/form-tester/
The cases in which it’s necessary to use AND in combination with a group of OR conditions are very rare. Most of the times it can be solved by rearranging your groups a bit. I want to understand your case so I can justify spending the extra development time to create more complexity. I want to make 100% sure that it’s necessary and there are no elegant solutions possible without it. I greatly appreciate your help.
here is a copy of my form: http://conditional-fields-cf7.bdwm.be/form-tester/?hash=1359cada87fd46e42737d3945f40bdf2
for example, you’ll see that I had to repeat all last lines instead of just writing something like:show [prix9] if [compagnie] equals "La Compagnie || Lux Aviation || Norse || ..."using the php syntax for OR
I’m looking forward reading your alternative but I’m used to conditional logic and couldn’t figure out how to make it easier.
(btw, it’s a cool tool to test a form)Sorry for the late reply. You might find this useful: https://conditional-fields-cf7.bdwm.be/advanced-conditional-logic-with-custom-javascript-functions/
This option is only available in the Pro version though.
Hi Jules, thanks for your answer. I was aware i could add custom JS with the pro version. I would be a better option (even a paid one) to deal with conditions on the front end as not everybody is about to use JS (and also access to functions.php file).
I’ll think about it. But you don’t need access to functions.php. You can add the JavaScript code straight in your form between script tags.
You’re right. Anyway, I wish you could add it a front-end setting. Would you need some funding for that?
The topic ‘Nested OR operator’ is closed to new replies.