Silent Submission of Google Forms

If you tuned in about half an hour ago, you’d have seen how we’re triggering channel creation in Slack based on a custom post type getting published. One of the other tricks we wanted to happen as a result of that was the creation of a Google Folder. There are a variety of ways to play this but some of the easier ones would require some options we have blocked on our VCU accounts. I could have gone around that via a personal account and then subsequent sharing but it seemed like it’d be more fun to do it this way.

I knew I could trigger script events based on form submissions and that I could use the data in the form as variables as well. I also knew I could fill out form variables via URL parameters.

What I didn’t know was whether I could submit a Google Form without actually hitting submit. Turns out you can.

Take your normal form URL.

You can get one of the pre-filled URL patterns like so . . .

Which gives you a URL like this. You can see my pre-filled response ‘fish tank’ at the end of the url.

Now to make it auto submit ‘fish tank’ you have to change one piece and add an element at the end. I’ll stack them over one another to better show the difference.

Note the move from viewform to formResponse and the appending of &submit=Submit at the end of the URL.

Now I can create a function to call that URL in WordPress every time a Project is published like so and subsequently I can write a Google Script to do what I need to do on that end.

function submitGoogleForm ($id, $post){
	$formUrl = '';
	$projectName =$post->post_name;
	$submit = '&submit=Submit';
	$fullUrl = $formUrl.$projectName.$submit;


add_action( 'publish_project', 'submitGoogleForm', 10, 2);

One thought on “Silent Submission of Google Forms

Comments are closed.