Quantcast
Channel: Snippets Archives - Gravity Wiz
Viewing all articles
Browse latest Browse all 196

Use Gravity Form Merge Tags in Your Post Content

$
0
0

Stop! There's a better way.

This snippet is available as a plugin with Gravity Perks, a suite of over 32 premium Gravity Forms plugins!

View this code snippet on GitHub.
gw-post-content-merge-tags-post-editor

Gravity Forms has excellent support for form confirmations. As always, Gravity Wiz aims to take that support a little further.

Gravity Forms provides an easy way to display personalized information via the “Text” confirmation type. You select which “merge tags” (which represent submitted form data) and place them in the text confirmation as desired. When the text confirmation is displayed, the merge tags will be replaced with the submitted data each merge tag represents.

But what if you wanted to do this on a separate confirmation page using the “Page” or “Redirect URL” confirmation types? You could readily pass the required data to the page via the “Pass Field Data Via Query String” option; however, while this option allows you to pass submitted data to the confirmation page, it does not provide a method for displaying that data on the confirmation page.

The uses of this snippet might not be immediately obvious. Here are the key points of functionality which will shed a little light onto how this snippet can be utilized effectively in the wild.

  1. Reclaim complete control over the styling of the redirect page while maintaining the ability to use Gravity Forms merge tags in the content of the page.

  2. Reuse the same confirmation page for multiple forms. For instance, you might have 25 forms on your site but would like to redirect users from all of those forms to a single, personalized “Thank You” page on submission.

  3. Implement persistent confirmation pages. For example, you could send the user an email including the confirmation page URL to their form submission, which they could save for future reference.

Ready to take your confirmation pages to the next level? Let’s dig in.

How do I get started?

  1. Gravity Forms v1.8.9 is required to use this snippet.
  2. Copy and paste the snippet into your theme’s functions.php file.
  3. This snippet requires some additional configuration. Read on.

Usage Instructions

You can now use merge tags in your post content! Check out the steps below to get started.

  1. Create your form.
  2. Create the confirmation page to which you will be redirecting.
  3. In the “Confirmations” tab of your Gravity form, set up a page redirect to the confirmation page you created.

    gravity-forms-set-up-a-page-redirect-to-the-thank-you-pageSet up a page redirect to the thank you page you created
  4. Now add the desired merge tags to the post content of the confirmation page. Any merge tag that can be inserted into the “Text” confirmation’s “Message” field, can be used in the post content of your confirmation page.

    Only the field label is required for these post content merge tags to work. For example, the default merge tag for an email field would be {Email:3}, where Email is the field label and 3 is the field id. Dropping the field id and just using the field label (like so: {Email}) is also supported. In fact, label-based merge tags are required if you will be using the same confirmation page for multiple forms. See below for more details.
    gw-post-content-merge-tags-post-editor
  5. Once you have your confirmation page completed, fill out the form you created. If everything was set up correctly, you will have a merge-tag-powered confirmation page!

    gravity-forms-post-content-merge-tags-thank-you-page

Advanced Usage

View this code snippet on GitHub.

Parameters

  • auto_append_eid (boolean or array) (required)

    The eid query string parameter is required for the post content merge tags to work. It is how the merge tags know which entry they should pull their data from. When the auto_append_eid argument is true (enabled by default), the eid parameter is automatically appended to the redirect URL for any form that is using the “Page” or “Redirect” confirmation type.

    Default value is true. Supports false or any array of form IDs for which the eid parameter should automatically be appended.

    Example: 'auto_append_eid' => array( 1, 7, 15 )

  • encrypt_eid (boolean) (required)

    Since there is a possibility that you will be displaying personally identifying information, set the encrypt_eid parameter to true to encrypt the eid parameter and prevent unauthorized users from guessing the confirmation URL for any given entry.

    Default value is false. Also supports true.

This code now supports a new {encrypted_entry_id} merge tag for use in notifications. This allows you to send the confirmation URL to the user with the encrypted eid parameter like so:

http://mysite.com/confirmation-page/?eid={encrypted_entry_id}

Tips for using a single confirmation page for multiple Gravity forms

If you have multiple forms that you would like to redirect to the same confirmation page, the first step is make sure you’ve set the confirmation for each form to redirect to your custom confirmation page.

It is important that the field labels for each form match the merge tag label in the confirmation page template. For example if your field label is Email, you’re merge tag would be {Email}. If you changed the field label to Email Address the merge tag for that form would be different and {Email} would no longer work.

This is another reason why you might consider setting an admin label for your form fields and using this instead of the field label when adding your post content merge tags. The admin label is less likely to change and also allows you flexibility on the field label between forms.

Can I use this with any Gravity form?

This snippet supports any Gravity form, including existing forms. Make sure that your field labels match the merge tags specified in the post content of your custom confirmation page and make sure your form redirects to this custom confirmation page.

How’d we do?

If you use it and like it, let us know. We’d love to hear the different ways you found this code useful!


Viewing all articles
Browse latest Browse all 196