I’m building a form that uses the same set of radio button answers for each question. When the form is submitted, I need to publish the total number of each type of answer on the confirmation page.
On top of that, I need to show a sum of the count for the first 2 types of Answers.
So something like:
You chose Answer A & B 10 times (Answer A 4 times, Answer B 6 times)
You chose Answer C 4 times
You chose Answer D 1 time
Is there a way to get the total count and use Merge Tags (using the Gravity Wiz perk Merge Tags perk) on the confirmation page?
I don’t know of a way to do that with Gravity Wiz, but I will tag them and hope they show up with something.
In general, you would need to use PHP to count the frequency that each option was selected, and then store that in a field in the form, so you can use that number on your confirmation page. I usually do this with the gform_pre_submission filter:
Here’s what I’ve set up in my functions.php to populate the fields (there will eventually be 35 fields like this):
// $_POST is the visible question, rgpost holds the answer for counting
function pre_submission_handler( $form ) {
$_POST['input_21'] = rgpost( 'input_18' );
$_POST['input_22'] = rgpost( 'input_20' );
}
add_action( 'gform_pre_submission_1', 'pre_submission_handler' );
If I want to use something like array_count_values($array), how do I get that array from each entry? I’ve gone through your docs and I’m just not finding that piece of the puzzle.
Creating the array using values from rgpost seems to be headed in the right direction but the empty values is a bit confusing. The inputs I’m storing the answers in are set us Number fields.
I’m assuming that if I can get the actual values in to the rgpost array, the rest should all fall in to place. Am I on the right track?