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):
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 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.
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:
gform_form_post_get_metaapplies 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
$childIdvariable is set manually. This is the form we are retrieving fields from.
$prefixvariable 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.