<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Dynamically Modify Checkbox/Radio Choices</title>
		<link>https://legacy.forums.gravityhelp.com/topic/dynamically-modify-checkboxradio-choices</link>
		<description>Gravity Support Forums Topic: Dynamically Modify Checkbox/Radio Choices</description>
		<language>en-US</language>
		<pubDate>Mon, 20 Apr 2026 12:00:43 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/dynamically-modify-checkboxradio-choices" rel="self" type="application/rss+xml" />

		<item>
			<title>leenkme on "Dynamically Modify Checkbox/Radio Choices"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamically-modify-checkboxradio-choices#post-53041</link>
			<pubDate>Wed, 21 Mar 2012 11:14:00 +0000</pubDate>
			<dc:creator>leenkme</dc:creator>
			<guid isPermaLink="false">53041@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Have a client who wants to use our plugin (an event calendar plugin) to dynamically list upcoming events in their Gravity Forms plugin for event registration. I took a look at GF and found this filter somewhat useful: gform_field_choices_# (where # is the form ID).&#60;/p&#62;
&#60;p&#62;This is the sample code I came up with for him (without the specifics for my form):&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;function testing_gform_field_choices( $choices, $field ) {

		if ( 1 == $field[&#38;#39;id&#38;#39;] ) { // 1 = the Field ID of the field you&#38;#39;re wanting to modify.

			unset( $field[&#38;#39;choices&#38;#39;] );

			$field[&#38;#39;choices&#38;#39;][] = array(
				&#38;#39;text&#38;#39; 			=&#38;gt; &#38;#39;Testing 1&#38;#39;,
				&#38;#39;value&#38;#39;			=&#38;gt; &#38;#39;Testing 1&#38;#39;,
				&#38;#39;isSelected&#38;#39;	=&#38;gt; false,
				&#38;#39;price&#38;#39;			=&#38;gt; false
			);

			$field[&#38;#39;choices&#38;#39;][] = array(
				&#38;#39;text&#38;#39; 			=&#38;gt; &#38;#39;Testing 2&#38;#39;,
				&#38;#39;value&#38;#39;			=&#38;gt; &#38;#39;Testing 2&#38;#39;,
				&#38;#39;isSelected&#38;#39;	=&#38;gt; false,
				&#38;#39;price&#38;#39;			=&#38;gt; false
			);
			$field[&#38;#39;formId&#38;#39;] = &#38;#39;DO_NOT_RUN&#38;#39;; // We don&#38;#39;t want to get into an endless add_filter loop, so change the ID to someting useless.
			$choices = GFCommon::get_radio_choices( $field, &#38;#39;&#38;#39;, &#38;#39;&#38;#39; ); // Rerun the GF script to make it look pretty again

		}

		return $choices;

	}
	add_filter( &#38;#39;gform_field_choices_1&#38;#39;, &#38;#39;testing_gform_field_choices&#38;#39;, 10, 2 ); // _1 = the FORM ID of the form you want to modify&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;So, I unset choices, add my &#34;dynamic&#34; choices, change the 'formID' to some junk value (so the filter doesn't run in an endless loop), get my new $choices variable and return it.&#60;/p&#62;
&#60;p&#62;It would be great if there was a &#34;pre_gfrom_field_choices&#34; filter at the head of the get_radio_choices and get_checkbox_choices functions. One that simply let us modify the $field['choices'] array. Doing it this way doubles the work... not a huge deal, but would be a good addition tot he code.&#60;/p&#62;
&#60;p&#62;Anyway, if that doesn't come to fruition, I hope the above code helps someone who wants to do something similar.&#60;/p&#62;
&#60;p&#62;Lew Ayotte
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
