Gravity Forms Field Template hero image

Nested Forms – Using Gravity Forms as a Field Template

We get the opportunity to use Gravity Forms on a lot of projects at iWitness Design, but often the “out of the box” options don’t achieve exactly what we need. In one particular case we wanted to be able to use a Gravity Form as a template for fields inside another Gravity Form. The kicker is that we wanted the entry meta to be stored to the primary (parent) form in the same way as if the fields originally belonged to it. This was for both code and visual reasons.

Check out some of the great options we tried before deciding to move in the custom code direction (or skip ahead to see our solution):

Nested Forms by Gravity Wiz

Gravity Wiz describes their plugin as, “A Gravity Forms Repeater Addon for simple or more complex forms. Create forms within forms for better management of complex data collection. Formception!”

The good – Super easy to use GUI.

The bad – entries are stored to the original form and linked to the parent form via gpnf_entry_ entry meta. This makes the entry data more difficult to work with programmatically.

Gravity Forms Repeater – currently in beta

Gravity Forms describes the repeater in the following way, “A repeater field is a collection of other Gravity Forms fields, combined together into a set that can then be used on a single form. The benefit is that when a user submits the form, the repeater field collection can be entered multiple times by the submitter, within the same single form submission.”

The good – repeater entries are stored very similarly to the normal form entries. The entries are differentiated by an index value in the entry meta.

The bad – due to the functionality being in beta, there is no GUI (fields must be coded), no conditional logic, and many other listed limitations.

Our Solution

We used a combination of the Gravity Forms PHP API along with the gform_form_post_get_meta filter to retrieve fields from the child form and add them to the parent. This allows us to take a complex set of fields and insert into a form any number of times. For our purposes we have a form where multiple co-applicants can apply for a loan. Each applicant has a complex set of fields that would have otherwise required tons of duplicate fields in the form editor. This way, we can create a co-applicant form template and use that to insert the co-applicant fields multiple times in the form!

We are really excited about the opportunities this solution opens up. We are working to combine this technique with the Gravity Forms Repeater functionality (mentioned above) to create a robust, advanced repeater field set.

If you are looking for help implementing a complex Gravity Form like this, be sure to reach out to us on our Contact page.

↓ Want to know how we did it? We geek out below ↓

Things to note about this code:

  • The gform_form_post_get_meta applies to all forms and can be made to apply to only one form by adding the parent form ID at the end of the function name like gform_form_post_get_meta_6
  • The $childId variable is set manually. This is the form we are retrieving fields from.
  • The $prefix variable is used to make sure the fields being added to the parent form are unique and don’t cause a conflict with fields from other forms.
  • This code is a concept and likely won’t work for you out of the box. Take some time to understand the code, customize it, and then test thoroughly.

We’re curious to hear how this blog post or code snippet might have helped you. If you’re willing to share your story, leave us a message

Interested in other ways we’ve used Gravity Forms? Read our blog post about how to use the Gravity Forms User Registration Add-On with Restrict Content Pro.


Want to join our mailing list?

We'll send helpful articles right to your inbox

2 thoughts on “Nested Forms – Using Gravity Forms as a Field Template”

  1. Great solution, Landon. I’ve explored this concept a bit myself.

    I’d love to hear more about what you were trying to do with the Nested Forms entry data programmatically? We have some handy helper functions and we’re eager for feedback about how to make this more a more enjoyable developer experience.

    1. Hi David,
      The form this idea is for uses a custom parameter (dbParam) to map entry data to an external database.

      Our goals were to:
      – Store entries in the database as if they belong to the parent form. The database mapping works well; this prevents us from having to modify it.
      – Keep the parent form’s appearance the same on the frontend and clean up the form flow on the backend.

      We’d be happy to give our feedback on your helper functions.

Leave a Comment

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

👋 iWitness Design is now Mission Lab!Learn More