# First value as default in populated radio buttons field

**URL:** <https://community.gravityforms.com/t/first-value-as-default-in-populated-radio-buttons-field/13441>\
**Category:** Get Help\
**Tags:** radio-buttons, default-value, acf, auto-populate, dynamic-population\
**Created:** [September 15, 2022, 11:02am UTC](https://community.gravityforms.com/t/first-value-as-default-in-populated-radio-buttons-field/13441 "2022-09-15T11:02:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user620cbe86a7f98947](https://avatars.discourse-cdn.com/v4/letter/u/ac91a4/32.png) [@user620cbe86a7f98947](https://community.gravityforms.com/u/user620cbe86a7f98947)\
**Post date:** [September 15, 2022, 11:02am UTC](https://community.gravityforms.com/t/first-value-as-default-in-populated-radio-buttons-field/13441/1 "2022-09-15T11:02:39Z")

</div>

I managed to pass the values of a ACF checkbox field (colors) to a GF radio button field, showing the colors blue (first value) and red (second value). Does anyone know how to set the first value (e.g. blue) as default choice in the radio button field? My code is below. So how can I preselect the first value of the `$radiobuttons` array?

```auto
add_filter( 'gform_pre_render_1', 'populate_radio_colors' );
add_filter( 'gform_pre_validation_1', 'populate_radio_colors' );
add_filter( 'gform_admin_pre_render_1', 'populate_radio_colors' );
add_filter( 'gform_pre_submission_filter_1', 'populate_radio_colors' );

	function populate_radio_colors( $form ) {
		if ( $form['id'] != 1 ) {
			return $form;
		}
$post_id = get_query_var('training')
$colors = get_field( 'colors' , $post_id );

    // declare the array
    $radiobuttons = array();

// set array
    foreach ($colors as $color) {
      $radiobuttons[] = array(
        'value' => $color,
        'text' => $color,
      );
    }

    //Add repeater values as radio button choices
    foreach ( $form['fields'] as &$field ) {
      if ( $field->id == 49 ) {
        $field->choices = $radiobuttons;
      }
    }

    return $form;
    wp_reset_postdata();
  }	

```

---

<div class="post-metadata">

**Author:** ![jimtrue](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/jimtrue/32/1405_2.png) [@jimtrue](https://community.gravityforms.com/u/jimtrue)\
**Post date:** [September 15, 2022, 11:58am UTC](https://community.gravityforms.com/t/first-value-as-default-in-populated-radio-buttons-field/13441/2 "2022-09-15T11:58:51Z")

</div>

Within your $colors loop where you’re defining the $radiobuttons array, you would want to add a check for the value you want to make the first choice (if you’re doing it for a specific color) and add ‘isSelected’ =\> true

I’m not a PHP developer (I just play one on support), but that is the option for making a choice selected from this article:

> **[Dynamically Populating Drop Down, Radio Buttons or Multi-Select Fields](https://docs.gravityforms.com/dynamically-populating-drop-down-or-radio-buttons-fields/)**
>
> The premise for this walkthrough is that we want to populate the options in a Gravity Form select field with all of the posts currently published on the site.

Under the section ‘Creating an Array of Choices’.

Hope that helps!

---

<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:** [October 15, 2022, 11:59am UTC](https://community.gravityforms.com/t/first-value-as-default-in-populated-radio-buttons-field/13441/3 "2022-10-15T11:59:16Z")

</div>

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