# Get selected radio button value

**URL:** <https://community.gravityforms.com/t/get-selected-radio-button-value/564>\
**Category:** Get Help\
**Tags:** radio-buttons, value\
**Created:** [December 10, 2018, 11:13pm UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564 "2018-12-10T23:13:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![asthyanax](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@asthyanax](https://community.gravityforms.com/u/asthyanax)\
**Post date:** [December 10, 2018, 11:13pm UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/1 "2018-12-10T23:13:25Z")

</div>

Hi,  
I’m lost on how to get a radio button selected value. I must be missing something but I can see how to get the values and the texts but not which one has been selected.  
Thanks

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [December 11, 2018, 12:34am UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/2 "2018-12-11T00:34:44Z")

</div>

To get it in the confirmation or notification, using the merge tag, you can use the “:value” modifier. If you are using the all fields merge tag you can do this:

`{all_fields:value}`

For individual fields, you can do this:

`{Choose One:28:value}` (that would work for field 28 where the field has a title Choose One)

Documentation (find “value” without the quotes):

> **[Merge Tags Archives](http://docs.gravityforms.com/category/user-guides/merge-tags-getting-started/)**
>
> In this documentation section, you will find articles explaining the different Merge Tags available such as {admin\_email} and {all\_fields}.

If you are trying to get the value somewhere else, please let us know where you need to get it. Thank you.

---

<div class="post-metadata">

**Author:** ![asthyanax](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@asthyanax](https://community.gravityforms.com/u/asthyanax)\
**Post date:** [December 11, 2018, 1:05am UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/3 "2018-12-11T01:05:53Z")

</div>

I meant in the code?

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [December 11, 2018, 1:45am UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/4 "2018-12-11T01:45:02Z")

</div>

**When** in the code? At what point in the form processing are you trying to access the selected value? Can you share with us what you’re trying to do? The more information the better. We’re happy to help point you in the right direction. Thank you.

---

<div class="post-metadata">

**Author:** ![asthyanax](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@asthyanax](https://community.gravityforms.com/u/asthyanax)\
**Post date:** [December 11, 2018, 2:08am UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/5 "2018-12-11T02:08:15Z")

</div>

I’m trying to assign the post format of a user generated post based on a radio button value.  
function change\_post\_format( $post\_data, $form, $entry ) {  
//something here  
}  
add\_filter( ‘gform\_post\_data’, ‘change\_post\_format’, 10, 3 );

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [December 11, 2018, 2:56am UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/6 "2018-12-11T02:56:35Z")

</div>

Sure. You can use `$selected_radio = rgar( $entry, '5' )` to get the value that was selected when the form was submitted. The code would look something like this:

```auto
add_filter( 'gform_post_data', 'change_post_format', 10, 3 );
function change_post_format( $post_data, $form, $entry ) {
	// Logging
	GFCommon::log_debug( __METHOD__. '(): The entry => ' . print_r( $entry, true ) );
	GFCommon::log_debug( __METHOD__. '(): Original post data => ' . print_r( $post_data, true ) );
	// assume radio button field is 5
	$selected_radio = rgar( $entry, '5' );
	if ( $selected_radio == 'gallery' ){
		// set the post format to gallery if the radio button value was gallery
		GFCommon::log_debug( __METHOD__. '(): Radio button matched value gallery.' );
		$success = set_post_format( rgar( $entry, 'post_id' ), 'gallery' );
	}
	GFCommon::log_debug( __METHOD__. '(): Possibly modified post data => ' . print_r( $post_data, true ) );
	return $post_data;
}

```

---

<div class="post-metadata">

**Author:** ![asthyanax](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@asthyanax](https://community.gravityforms.com/u/asthyanax)\
**Post date:** [December 11, 2018, 3:32am UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/7 "2018-12-11T03:32:24Z")

</div>

Thank you so much 🙂

---

<div class="post-metadata">

**Author:** ![asthyanax](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@asthyanax](https://community.gravityforms.com/u/asthyanax)\
**Post date:** [December 11, 2018, 6:42pm UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/8 "2018-12-11T18:42:56Z")

</div>

Ok I had to make some changes but that worked. Apparently I can’t set the post format with gform\_post\_data…I was trying to use $post\_data[‘post\_format’] = ‘quote’ but doesn’t look like it’s available. I could change a post status, post content etc…not the format. So I did it with gform\_after\_submission and it works just great.  
Thank you for your help.

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [December 11, 2018, 7:13pm UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/9 "2018-12-11T19:13:10Z")

</div>

Thank you for the update.

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 4, 2022, 5:41pm UTC](https://community.gravityforms.com/t/get-selected-radio-button-value/564/10 "2022-01-04T17:41:39Z")

</div>


