<?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: Drop down dynamic population from single line text</title>
		<link>https://legacy.forums.gravityhelp.com/topic/drop-down-dynamic-population-from-single-line-text</link>
		<description>Gravity Support Forums Topic: Drop down dynamic population from single line text</description>
		<language>en-US</language>
		<pubDate>Mon, 20 Apr 2026 10:10:52 +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/drop-down-dynamic-population-from-single-line-text" rel="self" type="application/rss+xml" />

		<item>
			<title>kyle on "Drop down dynamic population from single line text"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/drop-down-dynamic-population-from-single-line-text#post-44928</link>
			<pubDate>Sun, 25 Dec 2011 19:11:34 +0000</pubDate>
			<dc:creator>kyle</dc:creator>
			<guid isPermaLink="false">44928@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I was intrigued by this one, so I took a stab at it.  Stealing a bit from &#60;a href=&#34;http://www.gravityhelp.com/forums/topic/counting-responses#post-43591&#34; rel=&#34;nofollow&#34;&#62;here&#60;/a&#62; and &#60;a href=&#34;http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields&#34; rel=&#34;nofollow&#34;&#62;here&#60;/a&#62; I came up with the following.&#60;/p&#62;
&#60;p&#62;First.. create your dropdown field.  Set the single option text to &#34;Add New City&#34; and the value to '' (blank).  Click Advanced, and give it a class of &#34;populate-city&#34;.&#60;/p&#62;
&#60;p&#62;Add a second field below that.  GIve it a title of New City.  Make a note of the field ID.  Set the Conditional tag to only show if your dropdown is set to ADD NEW CITY.&#60;/p&#62;
&#60;p&#62;Then, in your functions.php file, add the following:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php

// update the &#38;#39;2&#38;#39; in gform_pre_render_2 to the ID of your form
add_filter(&#38;#39;gform_pre_render_2&#38;#39;, &#38;#39;populate_cities&#38;#39;);

function populate_cities($form){

    foreach($form[&#38;#39;fields&#38;#39;] as &#38;amp;$field){

        if($field[&#38;#39;type&#38;#39;] != &#38;#39;select&#38;#39; &#124;&#124; strpos($field[&#38;#39;cssClass&#38;#39;], &#38;#39;populate-city&#38;#39;) === false)
            continue;

        // get previous entries user-added cities
        // update the 4 below to the field ID of your &#38;quot;New City&#38;quot; field
        $cities = get_entry_field_values(4, $form[&#38;#39;id&#38;#39;]);

         // update &#38;#39;City Dropdown
        $choices = array();

        foreach($cities as $city){
            $choices[] = array(&#38;#39;text&#38;#39; =&#38;gt; $city[&#38;#39;value&#38;#39;], &#38;#39;value&#38;#39; =&#38;gt; $city[&#38;#39;value&#38;#39;]);
        }
        $choices[] = array(&#38;#39;text&#38;#39; =&#38;gt; &#38;#39;Add New City&#38;#39;, &#38;#39;value&#38;#39; =&#38;gt; &#38;#39;&#38;#39;);
        $field[&#38;#39;choices&#38;#39;] = $choices;

    }

    return $form;
}

function get_entry_field_values($field_id, $form_id) {
    global $wpdb;

    $tablename = $wpdb-&#38;gt;prefix . &#38;#39;rg_lead_detail&#38;#39;;

    return $wpdb-&#38;gt;get_results($wpdb-&#38;gt;prepare(&#38;quot;SELECT value FROM $tablename WHERE form_id = %d AND field_number = %d&#38;quot;, $form_id, $field_id), ARRAY_A);         

}
?&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;You may want to sort the choices array, and check for duplicates, not to mention make sure the formatting [capitalization, etc.] is correct, but I'll leave that up to you.  When someone goes to fill out the form, they'll see a list of previously added cities.  They can choose that or choose &#34;ADD NEW CITY&#34; and use the input field that appears to enter their city name.  &#60;/p&#62;
&#60;p&#62;Hope it helps.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>MiikkaMakio on "Drop down dynamic population from single line text"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/drop-down-dynamic-population-from-single-line-text#post-44922</link>
			<pubDate>Sun, 25 Dec 2011 03:14:26 +0000</pubDate>
			<dc:creator>MiikkaMakio</dc:creator>
			<guid isPermaLink="false">44922@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Anyone?&#60;/p&#62;
&#60;p&#62;I've made couple changes to the names of the fields.. I know this is not too difficult thing but can't get it working!&#60;/p&#62;
&#60;p&#62;What would I need to add to get the dynamic population to work for the 'Kaupunki' drop down?&#60;br /&#62;
If the Kaupunki that the form user wants to select is not ready in the drop down list, he would be able to write to the 'Kaupunki jos ei listalla' and next user of the form would see that one in the 'Kaupunki' drop down.&#60;br /&#62;
I tried to follow the guide and read bunch of topics many times, but didn't quite get how I should determine that it takes the text from the 'Kaupunki jos ei listalla' etc.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>MiikkaMakio on "Drop down dynamic population from single line text"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/drop-down-dynamic-population-from-single-line-text#post-43993</link>
			<pubDate>Wed, 14 Dec 2011 01:55:36 +0000</pubDate>
			<dc:creator>MiikkaMakio</dc:creator>
			<guid isPermaLink="false">43993@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hey,&#60;/p&#62;
&#60;p&#62;I've been struggling with the dynamic population thing for some time. Trying to populate a drop down from a single line text -field.&#60;/p&#62;
&#60;p&#62;What would I need to add to get the dynamic population to work for the 'City' drop down?&#60;br /&#62;
If the City that the form user wants to select is not ready in the drop down list, he would be able to write to the 'City if not in the list' and next user of the form would see that one in the 'City' drop down.&#60;br /&#62;
I tried to follow the guide and read bunch of topics many times, but didn't quite get how I should determine that it takes the text from the 'CIty if not in the list' etc.&#60;/p&#62;
&#60;p&#62;FORM: &#60;a href=&#34;http://www.vaihtoon.fi/WordPress/share&#34; rel=&#34;nofollow&#34;&#62;http://www.vaihtoon.fi/WordPress/share&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Help needed, thanks!&#60;/p&#62;
&#60;p&#62;-Miikka
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
