We have had a couple of requests from Gravity Forms users that wanted to know how to submit a form automatically once the form page loads.
In some cases, they are passing data via a query string and all they need is for that data to populate the form and be submitted.
Use Case Example
One use case I can think of is a simple solution for employees to clock in and out. They log in to their account, and click the “clock in” button which is preloaded with a URL and any necessary parameters. I’ve demonstrated this below.
To get this to work you only need an HTML field in your form and the code snippet below.
Setting Up Your Form
You can add whatever fields you’d like to your form, but for this to work, you must have an HTML field with the code below added to the content field.
Below is the code snippet you will need.
To make the code work you will need to make two modifications after pasting it into your HTML field.
- Change ID# on line 24 to your forms actual ID number
- Change the delay time on line 27, currently set to 500 which is half a second
Additional Code Snippet
If you prefer to not have a delay in your submission and instead have the form submitted as soon as the form renders, you could use the snippet below.
Just be sure to replace ID# with your forms ID number.
The Wrap Up
I’m sure there are many other use cases where having the ability to auto-submit a Gravity Forms form is necessary, and if you have one of those cases, hopefully, this solution will work for you!
If you have any questions or need additional assistance, please use the comments below.