Automating document creation by replacing ‘direct replacement’ and ‘conditional content’ merge tags in an underlying document template, based on a person’s form inputs, can significantly streamline workflows (let’s call this the Orthodox Approach). The use of natural language prompts to obtain an output with AI tools like ChatGPT can likewise significantly streamline workflows (let’s call this the AI Approach).

The Orthodox Approach is excellent for consistent, structured, and dependable output. The AI approach, when used well, can be excellent for the summarisation, correction, or other manipulation of a user’s input, which can be particularly useful where a form is collecting significant volumes of free-text user input and including it in the documentary output. It can also be excellent for the generation of content based on sufficiently-precise prompts which, again, can be included in the documentary output.

Wouldn’t it be awesome if we could implement, within WordPress, a hybrid approach to document automation that leverages the best of both approaches, producing docx output for review and, if required, further editing. By ‘hybrid approach’, we’re talking about a form containing fields that collect data for ‘direct replacement’ and ‘conditional content’ merge tags in an underlying document template, as well as fields in the same form that obtain AI-generated content on the fly that can be used in the documentary output.

This is, in fact, possible right now, using a combination of WordPress plugins. It can be achieved with two alternative combinations of plugins, namely:

In this post, Part 1 of a two-part series, we’ll explain the first approach. In Part 2, coming soon, we’ll explain the second approach.

Gravity Forms + GravityWiz’s Gravity Forms OpenAI + GravityWiz’s Populate Anything + GravityMerge’s GM Templated DOCX

Summary of plugin usage

Gravity Forms, Populate Anything, and GM Templated DOCX, are all paid plugins. GravityWiz’s Gravity Forms OpenAI plugin is free.

In a nutshell, these plugins are used for these purposes:

  • Gravity Forms: form creation
  • Gravity Forms OpenAI: sending a prompt, based on a person’s prior form inputs, to OpenAI and obtaining a response
  • Populate Anything: using live merge tags to show the OpenAI response within the form before the form is submitted (thereby enabling immediate review and further prompting if required)
  • GM Templated DOCX: creation of the docx output; the person’s form field inputs and the OpenAI response help determine the ultimate content of a pre-existing underlying docx template that has been uploaded to WordPress through the plugin’s functionality.

Detailed walkthrough

To explain how this all works, I’m going to provide a detailed walkthrough that leverages a simplified version of a form I’ve used in the past. The form is one I created on StopLookGo Privacy, well before the likes of ChatGPT, to get summaries of statutory provisions relating to the collection, use and sharing of information by agencies, into a WordPress database. Each form entry creates a post. In the past, I had to manually write the summary of each statutory provision. Now, with OpenAI and ChatGPT, I can use AI to write the summary, and I can review and edit that summary if I wish before submitting the form entry and getting it into my database of statutory provisions. For the purposes of this walkthrough, I’m also going to make the full and consistently formatted summary available as a DOCX download.

To make this a reality, I’m going to import a copy of the form into this website. Then I’m going to modify it so that the full text of a statutory provision can be pasted into the form, with that text being sent off to OpenAI for processing. OpenAI’s summary will populate another field in the form before I submit the form. That workflow will enable me to edit the summary if I need to before submitting it. When the form is submitted, the form entry will create a consistently formatted post and the statutory summary will be immediately available as a DOCX download.

This walkthrough assumes that these plugins have been installed and activated: Gravity Forms, Gravity Forms OpenAI, Populate Anything, and GM Templated DOCX. Note that use of the Gravity Forms OpenAI plugin requires you to enter an API key (which you get from OpenAI) and to have set up a payment mechanism in OpenAI.

Step 1 – Create your form with the fields you need in the normal way, and a field for your response from OpenAI

Usually the first step in this ‘hybrid orthodox+AI document automation process’ would be the creation of your form in the orthodox way. I’ve already done that. Here’s what the form looks like before I modify it (I’ve disabled the Submit button to avoid spam entries):

As you can see, there’s a ‘Summary’ field into which, previously, I had to manually enter a summary of the statutory provision (I’d do that separately in a plain text editor, and then paste my summary into the form field).

In the backend of the site, I’ve made a copy of this form, and I’ve changed two things. First, I’ve renamed the ‘Summary’ field as ‘Copy and paste full text of statutory provision’. Second, directly beneath that field, I’ve added another paragraph field, with the field label ‘AI-generated summary of statutory provision’. I’ve done this because we’ll be using the first paragraph field to copy and paste the full text of the statutory provision, and the second paragraph field will be used as a container to show OpenAI’s response to our prompt. So now, on the front end, we’ll see these two fields within the overall form:

Step 2 – Create a feed with the Gravity Forms Open AI plugin

Within the ‘Settings’ for my form, there’s an ‘OpenAI’ option. That’s where we create the feed we need to send a prompt to OpenAI and get a response from OpenAI. Here’s how I’ve set it up:

Step 3 – Use the live merge tag as the default value in a paragraph text field

In the screenshot above, you can see we’ve selected the option ‘Enable Merge Tag’. Because we have Populate Anything installed and activated, we can use the merge tag as a live merge tag. In our case, we take the live merge tag ‘@{:FIELDID:openai_feed_2}’, we replace ‘FIELDID’ with ’18’, and we add @{:18:openai_feed_2} as the default value in our second paragraph field (‘AI-generated summary of statutory provision’). We’ve replaced ‘FIELDID’ with ’18’ because 18 is the ID of our first paragraph field into which we copy and paste the full text of the statutory provision. If any change is made to that field, our openAI feed will refresh, thereby sending our prompt to OpenAI and receiving a response. (And here’s a tip: if you don’t like what you first get back from OpenAI, you can have another crack by adding a space to that field.)

This is how things look in the form editor (note that this shows the field settings for our second paragraph field, ‘AI-generated summary of statutory provision’):

By this stage, our form is functional on the front end, in that it will send our prompt to OpenAI and receive a response. However, we still need to add our docx download option, using the GM Templated DOCX plugin.

Step 4 – Create a docx template, upload it to GM Templated DOCX (a.k.a. GravityMerge), link the template to the form, and set our confirmation page

For the purposes of this post, I’ve created a simple docx template in Microsoft Word that looks like this:

I’ve uploaded that template to WordPress via GravityMerge’s ‘Upload templates’ option, I’ve mapped the template to the form through the Form > Settings > GravityMerge options, and I’ve set the form confirmation to go to a separate page which contains the shortcode that enables the user to download the entry as a docx file or email it to themselves. (These processes are all explained in more detail in the GM Templated DOCX (GravityMerge) documentation.)

With these steps all in place, our hybrid orthodox+AI document automation is ready to go! Here’s a quick demo video showing the automation in action:

Isn’t that awesome? We can now leverage the strengths of orthodox document automation together with the power of AI-generated content, all within the WordPress and Gravity Forms ecosystem.

Sign up to our newsletter

Get new blog articles and other helpful information delivered to your inbox, pronto. We won't send you crud, and you can unsubscribe at any time.

See our privacy statement for further information on how we handle your information.