I have a form built with gravity forms that asks 5 questions, each with 2 answers.
Each answer corresponds to a category, and so I want to be able to add some conditional logic so that the confirmation sends to a different page depending on which category has more answers.
Form is here: https://90daysfromretirement.com/medicare-advantage-vs-medicare-supplement/
The two categories are "Advantage" and "Supplement" – so dependng on the answer, so whichever category has more responses (3 or greater) then the confirmation will redirect them to the appropriate page.
Problem is I can’t figure out how to Count the values for each and run logic off it. I don’t think it’s possible with any gravity forms add-ons I’ve found, and I haven’t been able to put the code together to do it.
Any suggestions?
2
Answers
Since you only have two options, you really only need to know the count of one and the total number of questions to know which value has been selected more.
For example, if you have 10 questions and "Advantage" choices are selected 6 times, you know that Advantage has more than "Supplement".
Here’s a snippet that should get you started. It will take a group of Radio Button fields, count the number of times a specified value has been selected, and populate that count into a Number field.
You can then use that Number field to apply conditional logic on your confirmations to redirect to the appropriate page (e.g. If Count is greater than 5, redirect to Advantage page. If Count is less than 6, redirect to Supplement page).
And here’s the source which may be updated in the future if other folks use this and experience any issues or need improvements: https://github.com/gravitywiz/snippet-library/commit/d34eb169da937981c4a1ea49bb8a36df023bff1b
The one thing missing from this snippet is PHP validation. You may not be concerned about people altering their count but it is possible without PHP validation.
You could try adding the following to your functions.php file