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.
This didn’t work for me for some reason
Hi Russell, which code snippet did you try, delay no delay? And did you add your form ID in place for ID#?
Yeah I tried both and amended the form id. I have some required fields on my form but i expected just to see the rejection message to say the required fields haven;t been completed (as if i had manually clicked the submit)
So what actually happened?
My only comment is clarification on the syntax regarding the form ID. Here’s my working code:
Your code was not included with your comment…
I thought I put it in there — I just replied to my post with the code (again?). In any case, I used the “additional code snippet” from above and used the substitution below. Per the directions above, I literally substituted the characters “ID#” with my form number “10”, resulting in the look below.(Perhaps it was just me, but it wasn’t exactly obvious to me what exactly should be replaced.)
This really is frickin’ cool! Thanks, Chris!
BTW, I’m considering removing the confirmation webpage notification once the form is automatically submitted — I can’t find how to disable or delete the confirmation. Any ideas?
Sorry, WordPress must be stripping the code when you publish your comment. Maybe a setting I need to sort out.
At any rate. When adding your form ID you would replace ID# with your forms actual ID number as you demonstrated above.
You can’t delete the default confirmation message or disable all confirmations, every form requires at least one confirmation.
You could set the redirect to take the user back to the initial page (or any page), in my example that would be the page where they click clock in or clock out.
OK, the code doesn’t show when I copy/pasted, please delete this post and edit my original to show my example above if you don’t mind.
Thank you for info.
by the way, how to put conditional logic?
For Example, submit button is not shown based on the conditional logic then pause or stop auto-submit.
is there an example can see and try?