Skip Navigation

[Resolved] Passing parameters between toolset and gravity forms

This thread is resolved. Here is a description of the problem and solution.

Problem:
A Gravity Form is inserted in the template for some post type which has a custom field, and the client wants to dynamically populate one of the form fields with the value from the custom field.

Solution:
This requires use of the Gravity Forms API, documented here: https://docs.gravityforms.com/using-dynamic-population/

A simple example is shown below: https://toolset.com/forums/topic/passing-parameters-between-toolset-and-gravity-forms/#post-1152079

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by ryanM-9 6 years ago.

Assisted by: Nigel.

Author
Posts
#1151822

Tell us what you are trying to do?
I have a range of products, each one displaying on a content template when selected... I have a gravity form at the bottom where the user adds their email address so we can send them more info on the product, I need the form to return this field [types field='q1'][/types] so I know which product the user wants information on.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link

#1151823

Here is the template

<div class="prodQ">
     <ul class="curve">
       <li><span>What is it?</span><span>[types field='q1'][/types]</span></li>
       <li><span>Who Is It For?</span><span>[types field='q2'][/types]</span></li>
       <li><span>Why Do You Need It?</span><span>[types field='q3'][/types]</span></li>
       <li><span>Where Does It Fit In?</span><span>[types field='q4'][/types]</span></li>
       <li><span>When Do You Need It?</span><span>[types field='q5'][/types]</span></li>
     </ul>
   </div>
  <div class="prodQEmail">Click Here For More Info</div>
  <div class="prodForm">
 [gravityform id="15" title="false" description="true"]
  </div>
</div>
#1151868

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Gravity Forms has three ways of passing values to fields within the form, as described here: hidden link

Via the shortcode wouldn't work, and neither would via query string unless you modify the page itself so that a URL parameter was added.

Which leaves using the final option, via a hook.

For the Toolset part, you should be able to get the current value of the q1 field like so:

global $post;
$q1 = get_post_meta( $post->ID, 'wpcf-q1', true );

You can then return the value of $q1 (instead of "boom!" as in the GF doc example).

#1152026
Screen Shot 2018-11-23 at 14.17.44.png
Screen Shot 2018-11-23 at 14.19.58.png

Hi Nigel, thanks for your help... but on the form reply it's just returning '$q1' rather than the actual info - as you'll see in the image.

This is the code in my functions:

global $post;
$q1 = get_post_meta( $post->ID, 'wpcf-q1', true );


add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
    return '$q1';
}
#1152079

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You are returning the string '$q1' not the variable $q1.

Also you need to include the code to retrieve the custom field in the GF hook.

Try this:

add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
	global $post;
	$q1 = get_post_meta( $post->ID, 'wpcf-q1', true );
    return $q1;
}

Except, you need to change 'your_parameter' to the Gravity Forms field you want to populate with the value of q1, as described in the GF documentation.

#1152223

My issue is resolved now. Thank you!