Ask your WordPress questions! Pay money and get answers fast! (more info)

Dynamically select option from dropdown field in Gravity Form WordPress

Hey there,

I have a form in Gravity forms. It loads in an eModal window. I need to dynamically select an option from a dropdown field, automatically set by the title of the page, i.e.:

dropdown options:
option 1
option 2
option 3

page title is "option 1" and therefore "option 1" is pre selected.

Any help would be massively appreciated!

Cheers,
Chris

Answers (3)

2015-12-07

Arnav Joy answers:

can you show us your site ?


crc comments:

Of course, sorry.

http://am.crctesting.com/locations/claremont/


crc comments:

Red 'Book your service' button within content will trigger the form. Note the form only contains the dropdown in question.


Arnav Joy comments:

yes I can see dropdown , so in this list all options are name of the pages ?


crc comments:

Hi Arnov,

Currently no, but eventually yes there will be a page for each option in the dropdown.

2015-12-07

Jayaram Y answers:

go to the advanced tab of the relevant field (the dropdown list) and ticked 'Allow field to be populated dynamically' and gave the parameter a name. Then opened up the relevant template and added the below code at the location where you wanted the form to appear:

global $post;
$title = $post->post_title;
echo do_shortcode('[gravityform id=1 field_values='dropdown_field=$title']');

Change the ID accordingly


crc comments:

Hey Jayaram,

the form is being add to the page using Easy Modal. So in the content field of easy modal I have the following code which loads the form.

[gravityform id="4" ajax="true"]

I have also tried the following which does work for text fields, but doesn't work with dropdown options:

[gravityform id="4" ajax="true" field_values="location-dropdown=balcatta"]

2015-12-07

Rempty answers:

First you need to configure your dropdown like this:
http://imgur.com/eskxdrE

You can change the paremeter name; but must be replaced in the next function


//gform_field_value_my_parameter_name where {my_parameter_name} is the name i set.

add_filter('gform_field_value_my_parameter_name', 'populate_my_parameter_name');
function populate_my_parameter_name($value){
global $post;
return get_the_title($post->ID);
}


crc comments:

Hey Rempty,

Brilliant, it worked - thank you!


Rempty comments:

Hello crc
Don't forget to vote for me to complete this question.
Thank you.


crc comments:

Hey Rempty,

This is my first time on the site. I have pressed up vote / down vote, however the next screen says:

"3 groups of people are allowed to vote:
The true elite who've earned 1% of all winnings on the site.
The top monthly experts.
The admins of this site.
All votes are public.

If you have already voted, you can not vote again.

Once an answer receives more downvotes than upvotes, then it is no longer displayed on the question page.

You are not allowed to vote."


Is this normal?


Rempty comments:

I think you must press "Vote to award prize"


crc comments:

ok, cool. I'll speak to admin and get it sorted as it's not allowing me to vote.


crc comments:

I've emailed Lawrence at support to find out why I can't vote, or what needs to happen next. I'll be in touch when I get a reply.

Thanks again for your help and sorry for the delay in completing the question.

Chris