Conditional statements for dummies!

By: Dave Briggs | Asked: 08/18/2024
ForumsCategory: General questionsConditional statements for dummies!
Dave Briggs asked 4 months ago
Hello all   I really think this must be me being really stupid, but I can't get very simple conditional statements to work on my form!   On my form, the user submits answers to some questions, those answers have scores associated with them, and the overall score is calculated at the end, by adding them all up and dividing them. So far so simple.   However I also want to associated a text 'level' to the score, and so want a field that takes the score and if it is a 1, give it the level "Passive", if it is 2 then "Developing" and so on up to 5.   So I have a text field in my form, and I have put the following into the calculation: [if [134]="1"]Passive[/if [134]] just to test it.    However on loading the preview of the form to test it, I am getting this error: Unexpected token "if".   Am sure I must be getting something very simple wrong here, but can't figure it out!   Thanks so much for any advice folk can give 🤦‍♂️   ~ Dave
5 Answers
Rob LeVineRob LeVine answered 4 months ago
Your syntax is not correct. Using your example it should be [if 134 equals="1"]Passive[/if 134]. See here.
Dave Briggs answered 4 months ago
Thank you so much Rob, but I am still getting the same error. Have attached a screenshot of how I have this set up - any pointers on what I have got wrong? Am pretty embarrassed to be having such difficult with something so simple.
Attachments
Rob LeVineRob LeVine answered 4 months ago
Oh, setting the default values. Well, I'm pretty sure you can't use conditional logic with a default value unless you're getting a parameter from the URL. What you want to do is easily accomplished with jQuery. Put a change event listener on the score field and update the text field when it changes. I'm assuming you are trying to do this on-the-fly, i.e., when someone changes the score while creating an entry. If, however, you're doing this when you first display the form, you can use frm_setup_new_fields_vars, though I doubt that's what you're trying to do.
Dave Briggs replied 4 months ago

Ah ok. I think I might need to find another way to do this, as that's a bit too technical for me.

Shawn Pery answered 4 months ago
If you don't want to write code, you can just create 5 "Leadership Level" fields and display them conditionally based on the "Leadership Score". So show this field if Leadership Score equals 1 etc.  Not the cleanest, but an easy workaround.
Dave Briggs replied 4 months ago

Yes that's a good shout. Right now I am putting the levels into a view after submission, which I have kind of managed to get working, but thanks!

Paul Morris answered 2 weeks ago
The answer is you can't put conditional statements in the calculation field. I get the exact same error when I do that. You can only use them in certain parts of the form:  https://formidableforms.com/knowledgebase/conditionals/ All I want to do is check if a question has been answered but I can't figure out how to do it. I guess you can't check for any conditions while the form is being filled out? Only after it's submitted?
Rob LeVineRob LeVine replied 2 weeks ago

It depends on what you mean by "if a question has been answered". What exactly is your user scenario?

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right