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.
https://docs.google.com/a/vcu.edu/forms/d/e/1FAIpQLScK2wgma6Oicv_ZY9i-6tg_w9RfEKKkgiAFJDw15jJnmr5ofQ/viewform?entry.1431785794

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.
https://docs.google.com/forms/d/e/1FAIpQLScK2wgma6Oicv_ZY9i-6tg_w9RfEKKkgiAFJDw15jJnmr5ofQ/viewform?usp=pp_url&entry.1431785794=fish+tank

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.
https://docs.google.com/forms/d/e/1FAIpQLScK2wgma6Oicv_ZY9i-6tg_w9RfEKKkgiAFJDw15jJnmr5ofQ/viewform?usp=pp_url&entry.1431785794=fish+tank
https://docs.google.com/forms/d/e/1FAIpQLScK2wgma6Oicv_ZY9i-6tg_w9RfEKKkgiAFJDw15jJnmr5ofQ/formResponse?usp=pp_url&entry.1431785794=fish+tank&submit=Submit

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 = 'https://docs.google.com/a/vcu.edu/forms/d/e/1FAIpQLScK2wgma6Oicv_ZY9i-6tg_w9RfEKKkgiAFJDw15jJnmr5ofQ/formResponse?usp=pp_url&entry.1431785794=';
	$projectName =$post->post_name;
	$submit = '&submit=Submit';
	$fullUrl = $formUrl.$projectName.$submit;

	file_get_contents($fullUrl);
}

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

Comments on this post

No comments.

Leave a Reply

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL