Populate Form B with Form A Values via Email Link

The Requirement

A client engaged us to create a method by which an automotive service department would receive a scheduling request via a Formidable form. The email that is sent with each new entry must have buttons to accept either the primary requested date or an alternate requested date. Clicking the acceptance button then triggers an email to the client informing them that their service has been scheduled for the specified date.

The day we finished providing the solution for this requirement, a very similar question was posed on the Formidable Slack community. The difference with this post is that the user wants to actually populate a second form with data from the first form by clicking a button in the first form's email. Since the poster is also a client, we responded to them privately with a variant of the original solution.

Since the Slack post is a public thread, another community member responded to it asking us to share the solution. This tutorial explains how we answered these requirements and hope it provides you with the key to solving your challenge.

Solution 1

This solution addresses the auto service center requirement. To reiterate, when car owners submit a request to the service department for maintenance, they provide two dates, a primary and alternate date. An email is sent from Form A, the appointment scheduling form, to the service department with the appointment details and two links to Form B, the appointment confirmation form. The first link is for the service manager to confirm the primary date, the second link confirms the alternate date.

Form A

The source code for the appointment scheduling email is:

If you are new to Formidable, this source code is added to the Send Email action's Message field. Let's breakdown the link.

The [siteurl] shortcode is provided by Formidable. It's best to use the shortcode to assure code portability. If you were to hard code the URL into the link, your email won't work if you migrate the form to another instance of WordPress, as may be the case when moving from a development to a production environment. By using the shortcode, the link will work no matter where you move the form because the URL is abstracted from the WordPress database.

The /appointment-confirmation/ slug is the permalink to the page containing Form B.

The ?pass_entry=[id]&date_confirmed=primary is a query string that passes values to Form B. The ?pass_entry=[id] passes the entry ID for the appointment request entry. The &date_confirmed=primary allows Form B to customize the confirmation email for either the primary or alternate appointment date. In our example, the date_confirmed parameter passes a different value for each link.

Easy enough so far?

Form B

Form B consists of multiple hidden fields and a single Submit button. Each of the hidden fields is populated with a default value from Form A using Formidable's [ frm-field-value ] shortcode. As an example, consider the customer's email address. The default value for the hidden email field is [ frm-field-value field_id=schedule_email entry=pass_entry ].

To display the shortcodes in the paragraph above, we added spaces between the square brackets and shortcode text. When you use these shortcodes for real, there are no spaces separating the square brackets from the shortcode text and parameters.

The shortcode's field_id parameter accepts either the field ID or field key from the Form A email field. We always use field keys to make certain that forms are transportable across WordPress instances. See this post to learn why: Writing Transportable Code: Keys vs. IDs.

The entry parameter picks up the entry id that is providing the field values from the query string we passed in the link from Form A's email. (?pass_entry=[id])

The confirmation email source code is:

Solution 2

For the second solution, the entire process is pretty much the same as Solution 1, except for how the data is used in Form B. The Solution 2 Form B actually displays the values from Form A instead of setting the default values for hidden fields. The same shortcode and syntax we use for the hidden fields is used to set the default values for standard fields.

A Tip For Testing

One thing to be careful of when testing passing values between forms is the syntax of the query string. It's a common practice to test forms in preview mode. When previewing a form, Formidable formats the preview URL as in this example:

Notice the query string in this example: admin.php?page=formidable&frm_action=edit&id=4.

In a query string, the first parameter is always preceded by a question mark (?). All subsequent paramters are preceded by an ampersand. If you want to test passing parameters in preview mode, first display the preview, then add any additional parameters to Formidable's query string preceding each parameter with an ampersand like this:


Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *