<?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: gform_pre_render upon previous dropdown condition?</title>
		<link>https://legacy.forums.gravityhelp.com/topic/gform_pre_render-upon-previous-dropdown-condition</link>
		<description>Gravity Support Forums Topic: gform_pre_render upon previous dropdown condition?</description>
		<language>en-US</language>
		<pubDate>Mon, 20 Apr 2026 15:06:54 +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/gform_pre_render-upon-previous-dropdown-condition" rel="self" type="application/rss+xml" />

		<item>
			<title>Chris Hajer on "gform_pre_render upon previous dropdown condition?"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_pre_render-upon-previous-dropdown-condition#post-140742</link>
			<pubDate>Sun, 03 Feb 2013 22:11:20 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">140742@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Very nice solution.  Thank you for posting your code.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Josh on "gform_pre_render upon previous dropdown condition?"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_pre_render-upon-previous-dropdown-condition#post-137821</link>
			<pubDate>Thu, 31 Jan 2013 20:31:57 +0000</pubDate>
			<dc:creator>Josh</dc:creator>
			<guid isPermaLink="false">137821@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Great, I did just that, see code below I used. Thanks&#60;/p&#62;
&#60;p&#62;Upon change of Dropdown A I have an ajax function request tha re-populated Downdown B with the filtered options based on the selection in Dropdown A.&#60;/p&#62;
&#60;p&#62;See the ajax jquery script... &#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[php]
countryFilter = function () {
    	var countryClass = &#38;#39;.dealer-country select&#38;#39;,
    		dealerClass  = &#38;#39;.dealer-name select&#38;#39;;
    	$(countryClass).change(function(){
    		var countrySelect = $(this),
    			country = countrySelect.val(),
    	    	dealerSelect = countrySelect.parents(&#38;#39;form&#38;#39;).find(dealerClass);
    	 	if(country != &#38;quot;default&#38;quot;) {
    	    	$.ajax({
    				type: &#38;#39;POST&#38;#39;,
    				url: &#38;#39;&#38;lt;?php echo admin_url(&#38;#39;admin-ajax.php&#38;#39;); ?&#38;gt;&#38;#39;,
    				data: { dealerCountry : country, action: &#38;#39;get_dealer_name&#38;#39; },
    				success: function(data){
    					dealerSelect.empty();
    					var options = $.parseJSON(data);
    					for(i=0;i&#38;lt;options.length;i++){
    						dealerSelect.append(&#38;#39;&#38;lt;option value=&#38;quot;&#38;#39;+options[i].value+&#38;#39;&#38;quot;&#38;gt;&#38;#39;+options[i].text+&#38;#39;&#38;lt;/option&#38;gt;&#38;#39;);
    					}
    					dealerSelect.removeAttr(&#38;#39;disabled&#38;#39;);
    				}
    	    	});
    	    }
    	});
    }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Which I fired using...&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[js]
$(document).ready(function () {
    	countryFilter();
    });
    $(document).bind(&#38;#39;gform_post_render&#38;#39;, function(event, form_id){
    	if(form_id == 3) {
        	countryFilter();
    	}
    });&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I then trimmed my original functions to...&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;[php]
// Dropdown A - Dealer Country
    add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;dropdown_dealer_country&#38;quot;);
    add_filter(&#38;quot;gform_admin_pre_render&#38;quot;, &#38;quot;dropdown_dealer_country&#38;quot;);
    function dropdown_dealer_country($form){
            if($form[&#38;quot;id&#38;quot;] != 3)
               return $form;
            $terms = get_terms(&#38;quot;dealer-country&#38;quot;);
            $items = array();
            $items[] = array( &#38;quot;text&#38;quot; =&#38;gt; __(&#38;#39;Select country...&#38;#39;,&#38;#39;theme&#38;#39;), &#38;quot;value&#38;quot; =&#38;gt; &#38;#39;default&#38;#39; );
            foreach($terms as $term)
        		$items[] = array( &#38;quot;text&#38;quot; =&#38;gt; $term-&#38;gt;name, &#38;quot;value&#38;quot; =&#38;gt; $term-&#38;gt;slug );
            foreach($form[&#38;quot;fields&#38;quot;] as &#38;amp;$field){
                if($field[&#38;quot;id&#38;quot;] == 6 ){
                    $field[&#38;quot;cssClass&#38;quot;] = &#38;#39;dealer-country&#38;#39;;
                    $field[&#38;quot;choices&#38;quot;] = $items;
                }
        	}
            return $form;
        }
        // Dropdown B - Dealer Name
    add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;dropdown_dealer_name&#38;quot;);
    add_filter(&#38;quot;gform_admin_pre_render&#38;quot;, &#38;quot;dropdown_dealer_name&#38;quot;);
    function dropdown_dealer_name($form){
            if($form[&#38;quot;id&#38;quot;] != 3)
               return $form;
            $items = array();
            $items[] = array( &#38;quot;text&#38;quot; =&#38;gt; __(&#38;#39;Select dealer...&#38;#39;,&#38;#39;theme&#38;#39;), &#38;quot;value&#38;quot; =&#38;gt; &#38;#39;default&#38;#39; );
            foreach($form[&#38;quot;fields&#38;quot;] as &#38;amp;$field){
                if($field[&#38;quot;id&#38;quot;] == 7){
        			$field[&#38;quot;cssClass&#38;quot;] = &#38;#39;dealer-name&#38;#39;;
        			$field[&#38;quot;choices&#38;quot;] = $items;
                }
        	}
            return $form;
        }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Then the finishing touch is the function which also goes in the functions.php - this is called by the ajax request...&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;[php]
function get_dealer_name_fn(){
    	$dealerCountry = $_POST[&#38;#39;dealerCountry&#38;#39;];
    	$dealers = get_posts(array(
            &#38;quot;post_type&#38;quot; =&#38;gt; &#38;quot;dealer&#38;quot;,
            &#38;quot;dealer-country&#38;quot; =&#38;gt; $dealerCountry,
            &#38;quot;post_status&#38;quot; =&#38;gt; &#38;quot;publish&#38;quot;,
            &#38;quot;orderby&#38;quot; =&#38;gt; &#38;quot;title&#38;quot;,
            &#38;quot;order&#38;quot; =&#38;gt; &#38;quot;ASC&#38;quot;,
            &#38;quot;posts_per_page&#38;quot;  =&#38;gt; -1
    	));
    	$items = array();
    	$items[] = array( &#38;quot;text&#38;quot; =&#38;gt; __(&#38;#39;Select dealer...&#38;#39;,&#38;#39;theme&#38;#39;), &#38;quot;value&#38;quot; =&#38;gt; &#38;#39;default&#38;#39; );
    	foreach($dealers as $dealer){
    		$items[] = array( &#38;quot;text&#38;quot; =&#38;gt; $dealer-&#38;gt;post_title, &#38;quot;value&#38;quot; =&#38;gt; $dealer-&#38;gt;post_title );
    	}
    	echo json_encode($items);
    	die;
    }
    add_action(&#38;#39;wp_ajax_get_dealer_name&#38;#39;, &#38;#39;get_dealer_name_fn&#38;#39;);
    add_action(&#38;#39;wp_ajax_nopriv_get_dealer_name&#38;#39;, &#38;#39;get_dealer_name_fn&#38;#39;);&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>David Peralty on "gform_pre_render upon previous dropdown condition?"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_pre_render-upon-previous-dropdown-condition#post-134261</link>
			<pubDate>Mon, 28 Jan 2013 17:48:13 +0000</pubDate>
			<dc:creator>David Peralty</dc:creator>
			<guid isPermaLink="false">134261@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;You would have to use JavaScript (AJAX) to do this, by capturing the choice and doing stuff to it and changing your second drop down.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Josh on "gform_pre_render upon previous dropdown condition?"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_pre_render-upon-previous-dropdown-condition#post-134196</link>
			<pubDate>Mon, 28 Jan 2013 15:18:31 +0000</pubDate>
			<dc:creator>Josh</dc:creator>
			<guid isPermaLink="false">134196@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hey guys, hope all is well at GF&#60;/p&#62;
&#60;p&#62;I have a question regarding gform_pre_render?&#60;/p&#62;
&#60;p&#62;I have dealer form. Which basically you choose your county, and then your dealer.&#60;/p&#62;
&#60;p&#62;Dropdown A = Dealer Country&#60;br /&#62;
Dropdown B = Dealer Name&#60;/p&#62;
&#60;p&#62;I have about 15 countries, and I am using get_terms in the gform_pre_render to list all my countries that I have assigned to a dealer...&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// Dropdown A - Dealer Country
add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;dropdown_dealer_country&#38;quot;);
add_filter(&#38;quot;gform_admin_pre_render&#38;quot;, &#38;quot;dropdown_dealer_country&#38;quot;);
function dropdown_dealer_country($form){

    if($form[&#38;quot;id&#38;quot;] != 3)
       return $form;

    $terms = get_terms(&#38;quot;dealer-country&#38;quot;);

    $items = array();
    $items[] = array( &#38;quot;text&#38;quot; =&#38;gt; __(&#38;#39;Select country...&#38;#39;,&#38;#39;mission-theme&#38;#39;), &#38;quot;value&#38;quot; =&#38;gt; 0 );

    foreach($terms as $term)
        $items[] = array( &#38;quot;text&#38;quot; =&#38;gt; $term-&#38;gt;name, &#38;quot;value&#38;quot; =&#38;gt; $term-&#38;gt;slug );

    foreach($form[&#38;quot;fields&#38;quot;] as &#38;amp;$field)
        if($field[&#38;quot;id&#38;quot;] == 6){
            $field[&#38;quot;choices&#38;quot;] = $items;
        }

    return $form;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;OK so the above works perfectly in Dropdown A&#60;/p&#62;
&#60;p&#62;Now what I am trying to do in Dropdown B is display all my dealer names.&#60;/p&#62;
&#60;p&#62;I have named each dealer custom post-type title with the name of the dealer, and this is what I am pre populating my secondary drop down with...&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// Dropdown B - Dealer Name
add_filter(&#38;quot;gform_pre_render&#38;quot;, &#38;quot;dropdown_dealer_name&#38;quot;);
add_filter(&#38;quot;gform_admin_pre_render&#38;quot;, &#38;quot;dropdown_dealer_name&#38;quot;);
function dropdown_dealer_name($form){

    if($form[&#38;quot;id&#38;quot;] != 3)
       return $form;

    $dealers = get_posts(array(
    	&#38;quot;post_type&#38;quot; =&#38;gt; &#38;quot;dealer&#38;quot;,
    	&#38;quot;dealer-country&#38;quot; =&#38;gt; $dealerCounty,
    	&#38;quot;post_status&#38;quot; =&#38;gt; &#38;quot;publish&#38;quot;,
    	&#38;quot;orderby&#38;quot; =&#38;gt; &#38;quot;title&#38;quot;,
    	&#38;quot;order&#38;quot; =&#38;gt; &#38;quot;ASC&#38;quot;,
    	&#38;quot;posts_per_page&#38;quot;  =&#38;gt; -1
    ));

    $items = array();
    $items[] = array( &#38;quot;text&#38;quot; =&#38;gt; __(&#38;#39;Select dealer...&#38;#39;&#38;#39;mission-theme&#38;#39;), &#38;quot;value&#38;quot; =&#38;gt; 0 );

    foreach($dealers as $dealer)
        $items[] = array( &#38;quot;text&#38;quot; =&#38;gt; $dealer-&#38;gt;post_title, &#38;quot;value&#38;quot; =&#38;gt; $dealer-&#38;gt;post_name );

    foreach($form[&#38;quot;fields&#38;quot;] as &#38;amp;$field)
        if($field[&#38;quot;id&#38;quot;] == 7){
            $field[&#38;quot;choices&#38;quot;] = $items;
        }

    return $form;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;...and as you can see in line 11, I have a variable in my get_posts array &#60;code&#62;&#38;quot;dealer-country&#38;quot; =&#38;gt; $dealerCounty&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;My question, is it some how posible to get the choice that is made in Dropdown A into my &#60;code&#62;$dealerCounty&#60;/code&#62; variable in my Dropdown B function?&#60;/p&#62;
&#60;p&#62;Any tips or help would be much appreciated as my Dropdown B is currently very long, and I need to filter it down by country.&#60;/p&#62;
&#60;p&#62;Many Thanks&#60;br /&#62;
Josh
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
