728x90

Viewed 197 times

 

-1

I want to use a multi-step form where the user enters their name in step one, then on step two the form will say "Hello, [name]" with the rest of the content and steps to follow.

Any ideas?

EDIT: I want to use data entered in step one on step 2. Reading GF documentation I think something like {[Field Name]:[field_id]} should work, but it does not. Digging further I found that this would only work once a form has been submitted already. So my question is, is there a way that will enable me to use the merge tags within the current form from data being submitted in a previous step?

pluginsplugin-gravity-forms

share  improve this question  follow 

edited Mar 30 '19 at 15:17

 

asked Mar 29 '19 at 20:17

 

Rowbee

32 bronze badges

  •  

    Welcome to WordPress development! Unfortunately it's unclear what you are asking as you didn't tell us what exactly you've tried so far and where you are stuck right now. Please update your question accordingly as otherwise it's just too broad. – leymannx Mar 30 '19 at 8:59

  •  

    That is fair. I am trying to use merge tags in a multi-step form. I want to use data entered in step one on step 2. Reading GF documentation I think something like {[Field Name]:[field_id]} should work, but it does not. Digging further I found that this would only work once a form has been submitted already. So my question is, is there a way that will enable me to use the merge tags within the current form from data being submitted in a previous step? – Rowbee Mar 30 '19 at 15:15 

 

 

0

This is possible with Live Merge Tags, a feature of Gravity Forms Populate Anything.

If you're looking to get your hands dirty with some code, Gravity Forms has an example of how this might work with a snippet on their docs for the gform_pre_render filter:

https://docs.gravityforms.com/gform_pre_render/#3-populate-field-with-values-from-earlier-page

 

gform_pre_render - Gravity Forms Documentation

The gform_pre_render filter is executed before the form is displayed and can be used to manipulate the Form Object prior to rendering the form.

docs.gravityforms.com

 

 

3. Populate Field With Values From Earlier Page

This example is for a two-page form. The data submitted from the first page is displayed on the second page as a preview. The second page has only one field, an html field that will be populated with the data from the first page.

add_filter( 'gform_pre_render_81', 'populate_html' );

function populate_html( $form ) {

    //this is a 2-page form with the data from page one being displayed in an html field on page 2

    $current_page = GFFormDisplay::get_current_page( $form['id'] );

    $html_content = "The information you have submitted is as follows:<br/><ul>";

    if ( $current_page == 2 ) {

        foreach ( $form['fields'] as &$field ) {

            //gather form data to save into html field (id 6 on my form), exclude page break

            if ( $field->id != 6 && $field->type != 'page' ) {

                //see if this is a complex field (will have inputs)

                if ( is_array( $field->inputs ) ) {

                    //this is a complex fieldset (name, adress, etc.) - get individual field info

                    //get field's label and put individual input information in a comma-delimited list

                    $html_content .= '<li>' .$field->label . ' - ';

                    $num_in_array = count( $field->inputs );

                    $counter = 0;

                    foreach ( $field->inputs as $input ) {

                        $counter++;

                        //get name of individual field, replace period with underscore when pulling from post

                        $input_name = 'input_' . str_replace( '.', '_', $input['id'] );

                        $value = rgpost( $input_name );

                        $html_content .= $input['label'] . ': ' . $value;

                        if ( $counter < $num_in_array ) {

                            $html_content .= ', ';

                        }

                    }

                    $html_content .= "</li>";

                } else {

                    //this can be changed to be a switch statement if you need to handle each field type differently

                    //get the filename of file uploaded or post image uploaded

                    if ( $field->type == 'fileupload' || $field->type == 'post_image' ) {

                        $input_name = 'input_' . $field->id;

                        //before final submission, the image is stored in a temporary directory

                        //if displaying image in the html, point the img tag to the temporary location

                        $temp_filename = RGFormsModel::get_temp_filename( $form['id'], $input_name );

                        $uploaded_name = $temp_filename['uploaded_filename'];

                        $temp_location = RGFormsModel::get_upload_url( $form['id'] ) . '/tmp/' . $temp_filename['temp_filename'];

                        if ( !empty( $uploaded_name ) ) {

                            $html_content .= '<li>' . $field->label . ': ' . $uploaded_name . "<img src='" . $temp_location . "' height='200' width='200'></img></li>";

                        }

                    } else {

                        //get the label and then get the posted data for the field (this works for simple fields only - not the field groups like name and address)

                        $field_data = rgpost('input_' . $field->id );

                        if ( is_array( $field_data ) ){

                            //if data is an array, get individual input info

                            $html_content .= '<li>' . $field->label . ': ';

                            $num_in_array = count( $field_data );

                            $counter = 0;

                            foreach ( $field_data as $data ) {

                                $counter++;

                                $html_content .= print_r( $data, true );

                                if ( $counter < $num_in_array ) {

                                    $html_content .= ', ';

                                }

                            }

                            $html_content .= '</li>';

                        }

                        else {

                            $html_content .= '<li>' . $field->label . ': ' . $field_data . '</li>';

                        }

                    }

                }

            }

        }

        $html_content .= '</ul>';

        //loop back through form fields to get html field (id 6 on my form) that we are populating with the data gathered above

        foreach( $form['fields'] as &$field ) {

            //get html field

            if ( $field->id == 6 ) {

                //set the field content to the html

                $field->content = $html_content;

            }

        }

    }

    //return altered form so changes are displayed

    return $form;

}

 

728x90

Gravity Forms uses merge tags to allow you to dynamically populate submitted field values and other dynamic information in notification emails, post content templates, and more! This article provides a quick grouping for reference, and directs you to the more detailed reference document for each tag.

Make sure you review the detail articles, as not all merge tags can be used in all the places that merge tags are accepted. For example, a selection of merge tags are not available for use as default values.

Form Related Merge Tags

See these articles:

Field Related Merge Tags

This article covers the basic format for adding fields with a merge tag, as well as all the possible modifiers that can be added.

See this article for information on the all_fields merge tag

Custom fields can be referenced by a merge tag also, see this article

See the following pages for details about merge tags for fields that provided by official add-ons:

Merge tags and modifiers that are specific to a particular field type can be found from within the specific field user guide documentation.

Entry Related Merge Tags

See these articles related for tags related to entries:

There is an older tag {entry_id} that is still supported, but the entry id can be obtained by the more powerful {entry} meta tag.

User Properties Merge Tag

See this article.

Post Field Merge Tags

See these articles:

Other Merge Tags

{date_mdy} Displays the current date in the MM/DD/YYYY format.

{date_dmy} Displays the current date in the DD/MM/YYYY format.

{pricing_fields} Displays the product/order table in a confirmation or notification.

{referer} Displays the address of the page which referred the user agent to the current page.

{admin_email} Displays email address configured on the WordPress > Settings > General page.

{helpscout:[prop]} Displays Help Scout conversation properties.

728x90

Dynamically filter and populate field choices and values with posts, users, taxonomies, terms, Gravity Forms entries, and databases. Pretty much anything!

This plugin is part of Gravity Perks, a suite of 32+ essential Gravity Forms addons with support you can count on.

What does it do?

GF Populate Anything allows you to dynamically filter and populate field choices and values with posts, users, taxonomies, terms, Gravity Forms entries, and databases. Pretty much anything! Choices and values can be filtered based on the values entered/selected in other fields allowing you to fetch and populate fresh, dynamic data as the user interacts with the form.

GF Populate Anything also provides support for Live Merge Tags which allows you to display dynamic, filterable data in your field labels, descriptions, and content.

Features

  • Dynamically populate field choices.
    Populate any choice-based field (e.g. Drop Down, Radio Buttons, Checkboxes) with dynamic, filterable data.
  • Dynamically populate field values.
    Automatically populate field values with dynamic, filterable data.
  • Dynamic filtering by user-specified input.
    Filter and populate fresh, dynamic data based on values/selections made in other fields.
  • Chain selects, radio buttons & more!
    Chain the available field choices based on selections in other fields.
  • Live Merge Tags.
    Add auto-updating merge tags anywhere inside your form (e.g. labels, descriptions, choices, values, HTML content).
  • Specialized, built-in data sources.
    Populate Posts, Users, Taxonomies, Terms, and Gravity Forms entries with specialized options for each. For everything else, populate directly from the WordPress database.
  • Flexible choice and input templates.
    Complete control over the populated value and label for choices and inputs.
  • Results preview.
    See the exact data that will be populated based on your filters right in the field settings.
  • Improve data accuracy.
    Improve accuracy by allowing users to select from an existing datasource rather than entering the information manually.
  • Automatic updates.
    Get updates and the latest features right in your dashboard.
  • Awesome support.
    We’re here to help! And we mean it.

Documentation

  1. How do I enable this functionality?
  2. Feature Details
    1. Populating Choices Dynamically
      1. Example Configuration
      2. Frontend
    2. Populating Values Dynamically
      1. Example Configuration
      2. Frontend
    3. Filtering Objects
      1. Filter Groups
      2. Filter Operators
      3. Filter Property
        1. Post
        2. Taxonomy Term
        3. User
        4. Gravity Forms Entry
        5. Database
      4. Filter Values
        1. Default
        2. Form Field Values
    4. Field Value Objects
      1. Example Field Value Object Configuration
      2. Example Field Value Object Frontend
    5. Live Merge Tags
      1. Fallback Modifier
      2. Example: Use Field Value in Another Field’s Label
      3. Example: Show Total in Submit Button
    6. Count the Number of Results
  3. Known Limitations
  4. FAQs
    1. Why aren’t users created with the Gravity Forms User Registration populating in my multisite?
    2. How do I display large entry queries?
    3. How do I add a placeholder or a blank space to the first populated option in a Drop Down?
    4. How do I add Checkbox Values as Choices?
    5. How can I differentiate similar items when populating into a Drop Down?
    6. How can I filter Posts those published in the last month?
    7. Why isn’t my Custom Post meta key selectable when filtering?
    8. Some Post meta values are missing from the filter drop down.
  5. Hooks
  6. Related Articles

How do I enable this functionality?

After GF Populate Anything is installed, you’ll want to enable “Populate Choices Dynamically” or “Populate Value Dynamically” for a given field in the Gravity Forms Form Editor. Here’s what that looks like when populating choices.

  Add a field that supports choices such as Drop Down or a text-based field such as Single Line Text.
  Enable dynamic population for the fields that you wish to dynamically populate.
  Select an object type that you wish to populate the field with.
  Optionally add filters to show the desired objects.
  Designate what object properties should be displayed by setting the Choice or Value Template.

Feature Details

Populating Choices Dynamically

If you wish to dynamically populate a choice-based field’s choices, you can do so by enabling “Populate choices dynamically” in the field’s settings.

Example Configuration

In the example below, we configured a radio button field to have its choices dynamically populated with users who have the “Administrator” role.

Frontend

Here’s what the configured radio button field looks like on the frontend.

Populating Values Dynamically

Populating values with GF Populate Anything is similar to how populating choices work. Enable “Populate value(s) dynamically” in the field’s settings and then configure it accordingly.

Example Configuration

In the example below, we configured a single line text field to have its value populated with the post title of the most recently added post.

You can dynamically populate a field’s choices and value(s) if it supports choices!

Frontend

Here’s what the configured single line text field looks like on the frontend.

Filtering ObjectsFilter Groups

Create groups of conditions that filter which objects are populated into the field. Add a condition to your group with the (+)/(-) icons to the right. All conditions in a group must be true for the group to match. Add another group by clicking the “Add Filter Group”. Objects that match any group will be populated into the field.

You can use the plus icon to add an AND filter condition. Adding Filter Groups creates an OR condition, but multiple filters in a single group are considered an AND condition.

Filter Operators

  • is
  • is not
  • > (greater than)
  • < (less than) * >= (greater than or equal to)
  • <= (less than or equal to)
  • contains
  • starts with
  • ends with
  • is LIKE
  • Available wildcards
  • % – Zero, one, or multiple characters
  • _ – Single character

Filter Property

Depending on the object type you select, you will have different properties to select from.

Post

  • Author
  • Parent Post
  • Post Content
  • Post ID
  • Post Status
  • Post Title
  • Post Type
  • Post Taxonomies (Dynamic)
  • Post Meta (Dynamic)

Taxonomy Term

  • Name
  • Parent Term
  • Slug
  • Taxonomy Term
  • Term ID
  • Term Meta (Dynamic)

User

  • Display Name
  • Role
  • User Email
  • User ID
  • User URL
  • Username
  • User Meta (Dynamic)

Security Note: On multisite installations, the User object type will only search users from the current site.

Gravity Forms Entry

  • Created by (User ID)
  • Entry ID
  • Fields (Dynamic)

Database

The Database Object Type’s properties are dependent on the table you select. Once you select a table, the properties will be all available columns on the MySQL Table.

Security Note: On single site installations, the Database object type is only available to administrators.

Filter ValuesDefault

After selecting the filter property, the Filter Value dropdown will be populated with a list of values that apply for that property. For example, if you are populating posts into a field and add a filter condition for the “Post Status” property, the Filter Value dropdown would be populated with a list of available post statuses (e.g. Draft, Pending Review, Published).

Form Field Values

Objects can also be filtered by values entered by the user when the form is filled out. After selecting the filter property and operator, select the desired field from the Form Field Values option group. When a user enters a value into the specific field, the objects populated into this field will be filtered by that value.

Field Value Objects

One common use case with GF Populate Anything is populating field values from a field with dynamically populated choices. You can do this by manually configuring the Object Type and Filters to use field values, but an even easier way is to use a Field Value Object.

Field Value Objects are available on any field that supports values when there is another choice-based field that has dynamically populated choices on the same form.

Example Field Value Object Configuration

In the example below, we wired up a single text field to display the user ID of the selected user in the radio field above it.

Example Field Value Object Frontend

Live Merge Tags

When GF Populate Anything is activated, any merge tag prefixed with an @ will be automatically replaced when its associated field is updated. Live Merge Tags can be used anywhere within your form (labels, descriptions, choices, values, and HTML content).

Fallback Modifier

Live Merge Tags support a special modifier :fallback which can be used to display content when the merge tag does not have a value. For example, if the user can optionally provide there name but you want to greet them regardless, you could use, Hello @{Name:1.3:fallback[there]}. If a user entered their name as David, it would read Hello David but if the user entered no name, it would read Hello there.

Example: Use Field Value in Another Field’s Label

Example: Show Total in Submit Button

Count the Number of Results

Use the {count} merge tag as a custom Value Template to populate the number of returned results instead of a value. This is useful for conditional logic where you want to show or hide a field based on how many objects exist.

For example, say you have an order form and the first 50 customers to purchase should receive a discounted price. Populate a hidden number field with the entry count.

That count can be used with conditional logic to show a Discount field to the first 50 customers.

 The “Only Show Unique Results” checkbox applies to the {count} merge tag. Uncheck this to count all entries.


Known Limitations

  • Dynamic choices are not yet available in conditional logic.
  • Populating to/from List fields is not supported.
  • Dynamic checkboxes are not available when exporting form data.
  • When populating from custom database tables, the primary key must be the first column of the database.

FAQs

Why aren’t users created with the Gravity Forms User Registration populating in my multisite?

When a user is created with the GF User Registration Add-On in a multisite install, they aren’t given a primary_blog meta key in the database, and Populate Anything specifically looks for that key to determine which site they belong to.

Use the gppa_object_type_user_limit_to_current_site hook as a workaround.

How do I display large entry queries?

By default, Populate Anything will only display up to 500 entries to guarantee the best performance but we do have a way of increasing this number.

Use the gppa_query_limit hook to adjust the maximum number of results that can be returned in your query.

How do I add a placeholder or a blank space to the first populated option in a Drop Down?

You can use the Placeholder setting on the Appearance tab to add a default choice:

Please note that Gravity Forms won’t let you add a space as the placeholder, but you can add a non-breakable space (&nbsp;) and it will create a blank choice.

How do I add Checkbox Values as Choices?

By default, Gravity Forms stores checkbox values as arrays separated by commas, and when Populate Anything pulls in those values, it populates them as they are stored. Luckily, we have a snippet that will populate checkboxes from an entry as choices: GP Populate Anything: Checkboxes from an Entry as Choices

How can I differentiate similar items when populating into a Drop Down?

When populating items with the same or similar choice labels, you can differentiate between the similar items by following these steps:

  1. Activate the Enable enhanced user interface option on the Appearance tab.
  2. Set the Choice Template’s Label to a custom value by selecting “Add Custom Value” from the Drop Down and then entering a custom template. For example, this will show the post title and the post ID.

The end result is a searchable Drop Down field with a unique identifier for each choice.

How can I filter Posts those published in the last month?

Populate Anything’s results can be filtered on relative dates with this snippet. It adds merge tags that can be used as Custom Values in this format: {INTEGER UNIT ago}. For example, to filter Posts from a month ago, use the merge tag {1 month ago}.

Why isn’t my Custom Post meta key selectable when filtering?

When a meta field is created with a custom field editor, such as Advanced Custom Fields, the newly created field is simply a placeholder. Until it is used in a post, it won’t be found by Populate Anything.

Some Post meta values are missing from the filter drop down.

By default, Populate Anything has a 1000 record limit when accessing meta values for a Post. We have a snippet that will let you modify that limit. To use it, change 1000 to whatever limit you’d like to set.

Hooks

Gravity Forms has hundreds of hooks. Check out our Gravity Forms Hook Reference for the most thorough guide to Gravity Forms’ many actions and filters.


 

How To Look Up Previous Entries with Gravity Forms - Gravity Wiz

Populate values from previous Gravity Forms entries when a user inputs matching values from that entry.

gravitywiz.com

 

gravitywiz.com/documentation/gravity-forms-populate-anything/

728x90

Unless otherwise noted, any code snippet in this post goes in your theme's functions.php file or a plugin for your custom functions.

Need a dynamic form? Here are three useful methods to pre-populate form fields using the Gravity Forms WordPress plugin.
Sometimes being lazy is a good thing, like creating one form to do three things instead of having three forms to keep track of. What if the form needs to load a different field dependent on which page the user is clicking from? Or dependent on the current page where the form is embedded? In this example, we will pre-populate a form field to conditionally display sections for Billing, Sales, and Support. Thankfully, the folks over at Gravityforms have made this a painless endeavor.

Cue each Section with a Dropdown Field

First, to cue the display of each conditional area, the for, needs an element with multiple options to select from; in this case a dropdown field will be used.

Add a dropdown to the form and in order to keep it unseen by users on the front end, set ‘Visibility’ to Hidden. Next, add Choices for each of the three sections, taking not of the value for each choice. Tick show values if a custom value is preferred. The value will be passed to the front end field and is what we will use to specify which conditional section to display.

Add Section Field with Conditional Logic

Next, go ahead and create a ‘section’ field for each conditional area: Billing, Sales, and Support. Be sure to check off the Allow field to be populated dynamically box, located in the advanced tab. Directly below, set the Parameter Name that will be used to call the corresponding field value. In this example we will use query_type.

Now, enable conditional logic so each section displays only when the corresponding dropdown choice is selected. Head to the advanced tab for each Section, check Enable Conditional Logic, and configure accordingly to display when the correct dropdown choice is selected.

Apply Parameter Values

The groundwork has been laid, and it is time to put this form to work. Here are three different ways to pre-populate, with a use case for each method.

Pre-Populate by Query String

After appending a query string to the page URL, we can cue the query_type parameter to deliver a default field value for the dropdown on our destination page. Going along with our example, let’s say we want to load the sales section any time the user is clicking from the Services page. On the Services page, we must build each destination link to call the ‘sales’ value for the previously set custom parameter:

http://example.com/contact-us/?query_type=sales

Pre-Populate by Shortcode

So what if we want to set the form to display the Billing section by default on our Billing page? One option is to include the standard Gravity Forms shortcode on the billing page, adding field_values and setting query_type equal to the designated dropdown value:
[gravityforms id=1 field_values='query_type= billing']

Pre-Populate by Hook

Time to hook it up. Here is the most recommended, versatile way to pre-populate Gravity Form fields, extending control of how and where field values will be pre-set. In this example, a conditional hook can be used in functions.php to look for the custom parameter and fills it with the desired value.

What if the form needs to display the Support section when it is located on the Support page? First, add a filter that includes the previously set query_type custom parameter: gform_field_value_query_type. This enables a custom_function to conditionally return the value support only if the page is titled Support:
add_filter( 'gform_field_value_query_type', 'custom_function' );
function custom_function( $value ) {
if( is_page('Support') ) {
return 'support';
}
}

Time to Get Nifty

There are tons of ways to extend Gravity Forms and create dynamic WordPress forms, making the plugin’s versatility a must-have. For a full scoop on using gform_field_value_$parameter_name Gravity Forms has put together a helpful guide.

+ Recent posts