How to programmatically calculate the frequency of values in option fields [RESOLVED]

Trying to figure out how to use Gravity Forms Radio button fields to derive the number of times the user has entered the first choice, the number of times the second choice and the number of times the third choice.

So I have created the form with multiple radio button questions with the three choices. The choices are different for each question - but the radiobutton ‘Value’ for each choice set to A, B or C depending on whether it is first, second or third choice.

At the end of the quiz I want to display the frequency of first choice across all the questions, frequency of second choice across all the questions, and frequency of third choice across all the questions. And depending on which one (i.e. A, B or C) is biggest, display a friendly message to the user.

For example:
Q1. How would you rate Gravity Forms functionality
A. Amazing , :radio_button: B. Adequate, C. Not adequate

Q2. How would you rate Gravity Forms value for money
A. Cheap , :radio_button: B. Average, C. Expensive

Q3. How would you rate Gravity Forms Support
:radio_button: A. Great , B. Average, C. Terrible

Results: to display
Number of ‘A’s = 1, Number of ‘B’s = 2 and number of ‘C’s = 0
You have rated the product predominantly ‘B’ based on the three Questions.

Hi Tim. You will need to do this yourself. You can use the gform_pre_submission filter as the time where you can count up all the values that were submitted to you:

First, add three hidden fields to the form. Those fields will not be visible on the front end form, but you will use them to store the totals for each choice.

In the code you write, tied to that filter, you can count the occurrence of each value, and then store those three values in the three hidden fields. Then you will be able to use those values in conditional logic in your notification email or your confirmation, to tailor the content based on the frequency of the submitted values.

If you need help with the code, once you get started, please let us know.

Hey Chris,

That is immensely helpful.

You guys provide great support – thanks and have a great break.


Hi Tim, Chris,

I’ve been able to get this working! now moving onto setting up the custom confirmations for each results. thanks so much.


May I ask how is this done? Been trying to achieve this to our quiz as well. Thank you.

Hi Don. I recommend opening a new topic and asking your question there. Share a link to the page on your site where we can see your form, and let us know what you’re trying to accomplish. Thank you.