gravityform use dropdown choice as variable in gform_pre_render - Wordpress Solution
[Solved] - gravityform use dropdown choice as variable in gform_pre_render - Wordpress Solution |
---|
Try following codes |
gravity forms : use previous dropdown choice as variable in gform_pre_render?
This question is mainly regarding [[LINK href="http://www.gravityhelp.com/documentation/page/Gform_pre_render"]]gform_pre_render[[/LINK]] which I am using in my functions.php pre-render 2 dropdowns, but applying some conditional logic manually to Dropdown B.
In a nutshell, I have dealer form. Which basically you choose your county, and then your dealer.
Dropdown A = Dealer Country
Dropdown B = Dealer Name // this will be hidden by conditional logic until Dropdown A is chosen.
I have about 15 countries, and I am using get_terms in this first gform_pre_render function to list all my countries that I have assigned to a dealer post, quite straight forward...
OK so the above function works perfectly in Dropdown A. Now what I am doing in Dropdown B is displaying all my dealer names (post titles) from my dealer post-type. I have named each dealer custom post title with the name of the dealer, and this is what I am pre-populating Dropdown B with... ...and as you can see in line 11, I have a variable in my get_posts array "dealer-country" => $dealerCounty My question, is it some how posible to get the choice that is made in Dropdown A into my $dealerCounty variable in my Dropdown B function? 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. Many Thanks Josh Solution - 1Hi Josh, If only GravityForm has options to set class for each choice (option)... but we can re-populate all options for dealer name with ajax based on selected county try this on functions.php, [[LINK href="http://pastebin.com/vaeubLgz"]]http://pastebin.com/vaeubLgz[[/LINK]] and ajax for getting post name/title based on county: [[LINK href="http://pastebin.com/JTkmTrUV"]]http://pastebin.com/JTkmTrUV[[/LINK]] we need to add class on gform_pre_render for our javascript function to both county and dealer name field, for example on above code I use 'dealer-county' for county and 'dealer-name' for dealer name; from the documentation add "cssClass" property to the field ( $field["cssClass"] ) and for dealer name, I think we don't need specific $dealerCounty category here, so we can populate all or none (since this field will be disable before county selected);
Solution - 2Are you looking to have this done without reloading the page? (i.e. ajax) Or are you breaking it up into two pages Solution - 3Josh, Maybe an idea is reload only content of Dropdown B with an AJAX call as Kyle says. But this would not be my idea. I would do my own form in this case and I will use AJAX easier. 1) Create a template with forms for this case 2) Create a page with an slug to be called 3) Include an AJAX call to fill it: |
Date: 2022-10-21 05:03:27 |
Category: Wordpress |