How to calculate to most value selected from the radio button quiz form

This is the same question as from this topic below.

I am trying to create a form with 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 and the number of times the fourth choice.

So I have created the form with multiple radio button questions with the four choices. The choices are different for each question - but the radiobutton ‘Value’ for each choice set to A, B, C & D 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, C & D) 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, D.Bad

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

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

Results: to display
Display the most selected value: Example-> Mostly “A” , Mostly “B”, Mostly “C” or Mostly “D” depending on the most selected value from the quiz form.

Actual Form from our staging site: https://staging.sleepdrops.com/cleversleep-coach/

It looks like you are using Quiz fields in that form? That makes it more difficult to accomplish than using regular radio button fields. Is there a reason you are using the Quiz fields there, such as using the ‘correct answer’ functionality, or the quiz scoring?

No reason at all, should I use a regular radio button instead?

Hi Don. If there is no feature of the Quiz Add-On required for the form, then yes, I recommend using individual radio button fields for all the questions. That will make it easier to count the frequency of the A, B, C and D selections.

Before you change that form over to regular radio button questions, can you export this form and send the json file to me at chris@rocketgenius.com ? I would like to see if we can count the frequency without having to worry about the quiz values.

You can see how to export a form here: Exporting a Form - Gravity Forms Documentation

Thank you.

Hi Chris, did you get my email? Thank you.

Hi Don. Yes I have it. I will reply to you here or in the email on Monday. Thank you.

Hi Don. Looking at the quiz you set up, we’re not going to be able to make that work with Quiz fields. It adds unnecessary complexity. There are only 15 questions, so my recommendation is to create a new form, using radio button fields, and on each field, check the box to “show values” and then add the A/B/C/D values as you had them. Once you have that, please export the form and send me that json file via email to chris@rocketgenius.com and I will show you how we can count the frequency of each answer, and then what you can do with those counts. Thank you.

I replied to your email Don. It’s easier to send you the form and the code there. Let me know here if you need help with that.

For reference:

[SITE REMOVED]

Hello Chris, I have 1 more concern, my conditional logic on confirmations is somewhat on value. I wanted it to be able to make a comparison of the Value of A, B, C, and D.

Example:

A > B, A > C, A >D = execute this confirmation.

I tried the merge tag

{Number A:17}
{Number B:18}
{Number C:19}
{Number D:20}

but still no luck.

How can I set the conditional logic for this situation? Thank you Chris.

Hi Don. You will have all the A, B, C, D totals in those fields 17-20. So you can use that in conditional logic for the confirmations. However, it sounds like you are trying to use more complex logic than the built in options will allow. The conditional logic rules will support an ANY or ALL configuration, but it does not allow comparisons between two fields. From your example, it sounds like you want to show one confirmation when A is greatest. And what happens if there is a tie?

For complex rules for the confirmation, you may need to use the gform_confirmation filter, and perform all your comparisons in PHP.

Hello Chris, yes if any of the field is A=B=C=D it will go to the “don’t fit” confirmation. Is it not possible to use field as a value on the conditional logic?

Somewhat like this on the screenshot value or the attached file?

Screenshot_2|690x341

Thank you Chris.

Hi Don. This will work: Screenshot by Lightshot

That is saying “If A is greater than all the other recorded numbers, use this confirmation.” Is that all you needed, or do you have other scenarios to consider?

Hello Chris, I tried that screenshot but the weird part is it always go to the “Mostly A” confirmation. Yes that’s all I need it’s either A,B,C or D is greater than the rest and if the condition didn’t match, they will go to the “don’t fit” confirmation. I will give you an update on this later and clear the caching of our site and CDN, as of now I am not at home. Thanks for this.

Hello Chris, this is really weird. I used those dynamic values but all I am getting is the first confirmation of Mostly A only. :frowning: Why this wont work?

Let’s focus on one submission. Pick an entry. What are the values stored for the A, B, C and D totals?

Also, please be sure you enable logging on the site while troubleshooting this: documentation for Enabling Logging: Logging and Debugging - Gravity Forms Documentation

Hello Chris, would this be enough? Let me know what you need. I am still having the result for Mostly A even though the conditional was set correctly.

(
[input_1_3] => Don
[input_2] => A
[input_3] => B
[input_4] => B
[input_5] => B
[input_6] => B
[input_7] => C
[input_8] => C
[input_9] => C
[input_10] => C
[input_11] => D
[input_12] => D
[input_13] => D
[input_14] => C
[input_15] => D
[input_16] => B
[input_17] =>
[input_18] =>
[input_19] =>
[input_20] =>
[input_21] =>
[is_submit_11] => 1
[gform_submit] => 11
[gform_unique_id] =>
[state_11] => WyJbXSIsIjQxNmI4YzI0MzM2OTg3MjI5YTY5MTAxYjc3ODAwYjU1Il0=
[gform_target_page_number_11] => 0
[gform_source_page_number_11] => 1
[gform_field_values] =>
)

2021-04-12 13:15:22.417924 - DEBUG → count_abcd(): input ID => matched A.
2021-04-12 13:15:22.418446 - DEBUG → count_abcd(): input ID => matched B.
2021-04-12 13:15:22.418890 - DEBUG → count_abcd(): input ID => matched B.
2021-04-12 13:15:22.419325 - DEBUG → count_abcd(): input ID => matched B.
2021-04-12 13:15:22.419766 - DEBUG → count_abcd(): input ID => matched B.
2021-04-12 13:15:22.420212 - DEBUG → count_abcd(): input ID => matched C.
2021-04-12 13:15:22.420680 - DEBUG → count_abcd(): input ID => matched C.
2021-04-12 13:15:22.421108 - DEBUG → count_abcd(): input ID => matched C.
2021-04-12 13:15:22.421546 - DEBUG → count_abcd(): input ID => matched C.
2021-04-12 13:15:22.421988 - DEBUG → count_abcd(): input ID => matched D.
2021-04-12 13:15:22.422450 - DEBUG → count_abcd(): input ID => matched D.
2021-04-12 13:15:22.422878 - DEBUG → count_abcd(): input ID => matched D.
2021-04-12 13:15:22.423305 - DEBUG → count_abcd(): input ID => matched C.
2021-04-12 13:15:22.423746 - DEBUG → count_abcd(): input ID => matched D.
2021-04-12 13:15:22.424171 - DEBUG → count_abcd(): input ID => matched B.
2021-04-12 13:15:22.424541 - DEBUG → count_abcd(): Returning values => A:1; B:5; C:5; D:4.
2021-04-12 13:15:22.424983 - DEBUG → GFFormsModel::save_entry(): Saving entry.
2021-04-12 13:15:22.427175 - DEBUG → GFFormsModel::save_entry(): Entry record created in the database. ID: 36.
2021-04-12 13:15:22.428174 - DEBUG → GFFormsModel::save_entry(): Saving entry fields.
2021-04-12 13:15:22.428651 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.2 - name).
2021-04-12 13:15:22.429094 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.3 - name).
2021-04-12 13:15:22.429522 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.4 - name).
2021-04-12 13:15:22.429935 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.6 - name).
2021-04-12 13:15:22.430346 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Name(#1.8 - name).
2021-04-12 13:15:22.430876 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 1. What time do you usually go to bed at night?(#2 - radio).
2021-04-12 13:15:22.431415 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 2. How long does it usually take you to fall asleep each night?(#3 - radio).
2021-04-12 13:15:22.431946 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 3. What time do you usually get up in the morning?(#4 - radio).
2021-04-12 13:15:22.432476 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 4. How many hours of actual sleep do you get at night?(#5 - radio).
2021-04-12 13:15:22.432996 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 5. How often do you have trouble sleeping because you cannot get to sleep within 30 minutes?(#6 - radio).
2021-04-12 13:15:22.433554 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 6. How often do you have trouble sleeping because you wake up in the middle of the night or early morning?(#7 - radio).
2021-04-12 13:15:22.434109 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 7. How often do you have trouble sleeping because you have to get up to use the bathroom?(#8 - radio).
2021-04-12 13:15:22.434662 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 8. How often do you have trouble sleeping because you cough or snore loudly?(#9 - radio).
2021-04-12 13:15:22.435201 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 9. How would you rate your sleep quality overall?(#10 - radio).
2021-04-12 13:15:22.435729 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 10. Have you been experiencing tossing and turning, restless sleep, or light sleeping?(#11 - radio).
2021-04-12 13:15:22.436268 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 11. How many times do you wake up during the night?(#12 - radio).
2021-04-12 13:15:22.436793 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 12. On average, how long are you wake for?(#13 - radio).
2021-04-12 13:15:22.437303 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 13. In the previous 18 months have you experienced any stress?(#14 - radio).
2021-04-12 13:15:22.437843 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 14. How would you rate your current stress levels?(#15 - radio).
2021-04-12 13:15:22.438359 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: 15. What type of stress are you experiencing? Were you?(#16 - radio).
2021-04-12 13:15:22.438873 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Number A(#17 - number).
2021-04-12 13:15:22.439332 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Number B(#18 - number).
2021-04-12 13:15:22.439801 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Number C(#19 - number).
2021-04-12 13:15:22.440258 - DEBUG → GFFormsModel::queue_save_input_value(): Queued field operation: Number D(#20 - number).
2021-04-12 13:15:22.444097 - DEBUG → GFFormsModel::save_entry(): Finished saving entry fields.
2021-04-12 13:15:22.527556 - DEBUG → GFCommon::is_spam_entry(): Result from Akismet: false
2021-04-12 13:15:22.527998 - DEBUG → GFCommon::is_spam_entry(): Is submission considered spam? No.
2021-04-12 13:15:22.535140 - DEBUG → GF_Background_Process::dispatch(): Running for gf_feed_processor.
2021-04-12 13:15:22.536223 - DEBUG → GF_Background_Process::dispatch(): Unable to dispatch tasks to Admin Ajax: Nothing left to process
2021-04-12 13:15:22.536710 - DEBUG → GFFormsModel::create_post(): Starting.
2021-04-12 13:15:22.537216 - DEBUG → GFFormsModel::create_post(): Stopping. The form doesn’t have any post fields.
2021-04-12 13:15:22.537626 - DEBUG → GFAPI::send_notifications(): Gathering notifications for form_submission event for entry #36.
2021-04-12 13:15:22.538048 - DEBUG → GFCommon::send_notifications(): Processing notifications for form_submission event for entry #36: Array
(
[0] => 606cf385b594b
)

(only active/applicable notifications are sent)
2021-04-12 13:15:22.538512 - DEBUG → GFCommon::send_notifications(): Notification is inactive, not processing notification (#606cf385b594b - Admin Notification) for entry #36.
2021-04-12 13:15:22.538966 - DEBUG → GFFormDisplay::handle_confirmation(): Sending confirmation.
2021-04-12 13:15:22.541044 - DEBUG → GFFormDisplay::handle_confirmation(): Executing functions hooked to gform_confirmation.
2021-04-12 13:15:22.541601 - DEBUG → GFFormDisplay::handle_confirmation(): Confirmation =>

















Results
A B C D
1 5 5 4

Mostly A's

Your patient’s sleep is good. It is important that your client keeps on this path, continue to monitor their sleep monthly. This could be as simple as sending them this form before the next
consultation or actively inquiring about their sleep when they come in for each consult. Sleep is the foundation to all health and wellbeing.
Remember the 4 most important questions to ask each consult are:
Do you have trouble going to sleep?
Staying asleep?
Or both?
Was it brought about by stress?
2021-04-12 13:15:22.542629 - DEBUG --> GFFormDisplay::process_form(): Executing functions hooked to gform_after_submission. 2021-04-12 13:15:22.547518 - DEBUG --> GFAPI::send_notifications(): Gathering notifications for gravityview/approve_entries/updated event for entry #36. 2021-04-12 13:15:22.547998 - DEBUG --> GFCommon::send_notifications(): Aborting. No notifications to process for gravityview/approve_entries/updated event for entry #36. 2021-04-12 13:15:22.549935 - DEBUG --> GFAPI::send_notifications(): Gathering notifications for gravityview/approve_entries/unapproved event for entry #36. 2021-04-12 13:15:22.550384 - DEBUG --> GFCommon::send_notifications(): Aborting. No notifications to process for gravityview/approve_entries/unapproved event for entry #36.

Also, I found this code on gravitywiz and edit it but still doesn’t give me the right output.

[gravityforms action=“conditional” merge_tag=“{Number B:18}” condition=“greater_than” value=“{Number A:17}”]
[gravityform action=“conditional” merge_tag=“{Number B:18}” condition=“greater_than” value=“{Number C:19}”]
[gravityform action=“conditional” merge_tag=“{Number B:18}” condition=“greater_than” value=“{Number D:20}”]
Mostly B’s
[/gravityforms]
[/gravityforms]
[/gravityforms]

It seems this works better. I finally got it. :slight_smile:

Is this working for you now with this code from Gravity Wiz?

As of now I can’t find a proper solution. :slight_smile: This code from GravityWiz is limited to the default confirmation only. I tried the {Number A:17:value} tag for the conditional but still didn’t give me the result that I want. :slight_smile: It’s like it wont check the Value from Number A/B/C/D from this merge tags {Number A:17}, {Number B:18}, {Number C:19} & {Number D:20}