Creating a Form from JSON (with PHP, within functions.php or custom plugin)

Hello,

I have a specific use-case. We’re developing a custom internal plugin that has a dependency on the GravityForms plugin. (So, we assume and check that GForms is installed on any site that uses this plugin.)

We need a pre-configured form for our plugin to work correctly. What is the best way to create that form on plugin activation?

My guess is that I can use the Export to JSON feature from my development site, include that JSON as an asset in my plugin, and programmatically import the form on plugin activation.

Can someone point me to an example of how to import a form programmatically using PHP?

Follow-up question: how can I prevent a single form from being modified by any user?

Thanks!

The GFAPI::add_form() method would be viable, but you’ll want to save the exported JSON from GFAPI::get_form() and not the form export, since the JSON structure is slightly different.

Not sure if you can create hidden forms that a user cannot modify.

1 Like