🎉  Build a workflow powerhouse. Learn more about our new Airtable integration.   🎉

July 15, 2015

Populate a Living Will from Gravity Forms

Do you spend time on the phone or sitting around the table with clients collecting all the information you need to generate a Living Will?  Those days are gone!  With a simple form on your website, you can collect all the necessary details from a client to automatically generate a Living Will for immediate review.

In this example we’re going to show you how you can collect information on your website using Gravity Forms and then automatically generate a Living Will document (in a Word document or PDF) using WebMerge.   You’ll be able to email the document directly to your client or to your office for review.

To get started, we’re going to setup our form in Gravity Forms.  We’ll be collecting all of the normal information like names, contact information.  Here’s what our form looks like:

To collect information about our Dependents and other “variable” number of items, we’re going to use Gravity Forms’ List field.  This allows the person filling out the form to add as many items as they need.  Here’s what we’re collecting for our Dependents:

Once we have our form setup, it’s time to setup our Will template in WebMerge. We’re going to use a Word document as our template.  Inside our Word document we’ll add our merge tags like {$name.first}, {$name.last}, {$email}, etc.  Gravity Forms uses subfields (when you see more than 1 input box for a single “field” on your form) and we reference those subfields using a dot, then the name of the subfield.

These merge tags are going to need to match the labels you are using for your form fields in Gravity Forms.  However, the labels are going to be automatically transformed to lower case and will replace spaces with underscores.  For example, if you use “Your Name” as the field label, you will want to use {$your_name.first} in your document.

Here’s what our Living Will template looks like:

For those “lists” that we have on our form, we’re going to “loop” through them in our document.  The naming scene for the subfields of the list is going to be the same (lowercase with no spaces) and we’re going to use the {tablerow} tag to build a table with the information (more information).  Here’s what that looks like:

Once we have the document all setup and ready to go, we’re going to upload it to WebMerge.  From the Documents page in WebMerge, click New Document, then type in a name.  On the next step, you’ll choose Office Document as the document type and pick your Word document to upload the file.

After you upload the file, you’ll be taken to the Settings tab.  Here’s where you can change the output document type (PDF or Word) and update the file name.  Feel free to change any of the settings here, but we’re going to jump to the Deliver tab.

On the Deliver tab, we’re going to setup the email delivery to go straight to our client.  Go ahead and Edit the default email delivery and update the To address to use the email merge field.  If you don’t have an email field in your document, choose the <<other>> option then type in the field (like {$email}) in the box.

Now that we have the document all setup in WebMerge, it’s time to integrate with our form!  Before you leave WebMerge, we need to grab the Merge URL for our document.  You can find this under the Merge tab.  Save this for later.

To automatically send submissions from our form to WebMerge, we’re going to add a little snippet of code to our Wordpress site.  Go ahead and copy & paste this code into your theme’s custom_functions.php or customizer.php file. You can edit this file under Appearance > Editor in Wordpress.

The only thing that you’ll need to edit is the part of the gf_send_to_webmerge() function where it is determining the $webmerge_url.  You’ll need to update the if statement to use your form ID and then the Merge URL for your document.

Go ahead and save that file and you are ready to do a test!  Simply submit a test submission for your form and the data will automatically be sent to WebMerge and the Living Will will be generated and emailed.  Here’s what our test looked like:

Congrats, you’re all done!  You can now integrate as many forms with WebMerge as you’d like.  Simply update that code snippet (the if statement) to include other Merge URLs and you can automatically populate all types of documents. 

Can you think of any other ways that you could use Gravity Forms and WebMerge to simplify your document generation?

7 min read

Ready to give Formstack Documents a try?
Start your Free Trial now!


Create Living Wills from Gravity Forms Now

By signing up here, you agree to our Terms of Use