# Count of specific choices selected in a range of radio button fields

**URL:** <https://community.gravityforms.com/t/count-of-specific-choices-selected-in-a-range-of-radio-button-fields/17306>\
**Category:** Get Help\
**Tags:** custom, gform\_pre\_submission, count\
**Created:** [April 19, 2024, 7:41am UTC](https://community.gravityforms.com/t/count-of-specific-choices-selected-in-a-range-of-radio-button-fields/17306 "2024-04-19T07:41:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5f69ca31839e6855](https://avatars.discourse-cdn.com/v4/letter/u/a4c791/32.png) [@user5f69ca31839e6855](https://community.gravityforms.com/u/user5f69ca31839e6855)\
**Post date:** [April 19, 2024, 7:41am UTC](https://community.gravityforms.com/t/count-of-specific-choices-selected-in-a-range-of-radio-button-fields/17306/1 "2024-04-19T07:41:49Z")

</div>

Hi,

I have a form which contains a list of radio button questions with the same 5 choices.

Can you please help me get a count of all the A’s, B’s, C’s, D’s and E’s.

I have tried using the gform\_pre\_submission approach that was provided in another thread but can’t seem to get the code right.

Here is what I have so far:

// change 258 to your form ID here  
add\_action( ‘gform\_pre\_submission\_258’, function ( $form ) {  
GFCommon::log\_debug( **METHOD**. ‘(): The POST =\> ’ . print\_r( $_POST, true ) );  
// What is the ID of the first radio button field that will be counted  
$first\_field = 55;  
// What is the ID of the last radio button field that will be counted  
$last\_field = 65;  
// initialize an empty array to hold all our radio button fields  
$radio\_fields = array();  
// loop through all the radio button fields and assign them to an array  
for ( $i = $first\_field; $i \<= $last\_field; $i++ ) {  
GFCommon::log\_debug( **METHOD**. “(): Counter is {$i}.” );  
$radio\_fields[] = rgpost ( 'input_’ . $i );  
}  
$counts = array\_count\_values ( $radio\_fields );  
GFCommon::log\_debug( **METHOD**. '(): COUNTS =\> ’ . print\_r( $counts, true ) );  
// store those counts in five fields in the form  
$\_POST[‘input\_5295’] = $counts[‘NCR - Cat 1: An activity likely to cause death/ SBO / SBI’];  
$\_POST[‘input\_5297’] = $counts[‘NCR - Cat 2 - An activity likely to cause other than death/ SBO / SBI’];  
$\_POST[‘input\_5298’] = $counts[‘NCR - Cat 3 - Contravention of admin requirements’];  
$\_POST[‘input\_5299’] = $counts[‘Compliant’];  
$\_POST[‘input\_5300’] = $counts[‘Opportunity for Improvement’];  
GFCommon::log\_debug( **METHOD**. '(): MODIFIED POST =\> ’ . print\_r( $\_POST, true ) );  
} );

I would really appreciate it if you took a look.

Thanks,  
Lloyd

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [May 19, 2024, 7:42am UTC](https://community.gravityforms.com/t/count-of-specific-choices-selected-in-a-range-of-radio-button-fields/17306/2 "2024-05-19T07:42:37Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
