Hey there stranger!

Sign up to get access.

How to Create a Google Form Automatically

About this Tutorial

How to create a form programmatically using Google Apps Script. I show you step-by-step how to create a form, set the title, add text items, and set the destination of the form to a specific sheet. This tutorial is perfect for anyone who wants to automate the process of creating forms, whether it's for templates, lead magnets, or recurring forms. No prior coding experience is required.

Video Transcript

00:00 So Brendan was asking how to create a form programmatically we want to show how to create a form programmatically in this video I did show this off in a testimonial sheet video.
00:11 I did create before in this custom menu We have create testimonial form and what that does is we can see here.
00:18 We can follow along item is create testimonial form, create form, and it does all of this stuff. It uses a form app, creates a new form, sets the title, sets required login false which is very important.
00:34 It then creates this sort of a title and then it creates text items. It will, let's actually run this from the beginning.
00:48 Let's, let's create this from scratch but I want to use this function on open in our sheet here. And I'll show you how to edit this, how to create it, and ultimately as a better team member you're happy to, you're more than welcome to copy the sheet.
01:05 Click below to copy the sheet. So we have a function on open. This will get us the custom menu. Create form menu I'll call it.
01:15 And then I'm just going to create a simple form called create form. We'll use the same actually, we'll change this simple.
01:24 Alright, go back to our existing testimonial sheets. What I need to do here first, let's grab this line form app dot create.
01:34 We'll use that. So we'll do function create simple form. The first thing we need is a variable form equals form app dot create new form.
01:50 This doesn't matter. Set the title as simple form set required login false. That is very important. That's the next thing we need.
02:00 We have this site name. And we don't need this in our case. We do want to add a text item set title.
02:06 So we'll do that form dot add text item set title. Title of simple form. We'll do that. What's next? Next we want to, okay, next is very important because we need to set the destination of the form to the sheet that's creating it.
02:31 If you happen to go up to tools, create a new form, this automatically creates the form and sets the responses to this sheet.
02:41 We programmatically do this through app script, it doesn't do that automatically. So we, what we need to do is we need to get the spreadsheet app dot get active spreadsheet, get the ID of this entire spreadsheet file.
02:52 Then we're going to grab the form app that destination type and call it and say this spreadsheet. This is the spreadsheet.
03:01 Sheet that you go to. This is the sheet ID that you set and it sets the form set dot set destination here.
03:09 So that is important to do. And now we need to quote unquote open this and create some items. In this case where in our testimonial example we wanted to ask people, the questions we asked them was what's your name, what's your role, what's your company.
03:28 But I want to do something a little bit different. I want to ask what is your name. Maybe we do item dot add text item set type.
03:41 It'll what's your email. Then what else do we need to do. We do not need this other stuff. Well actually this is really helpful.
03:59 We will grab this and use this again. So what this is doing is saving the ID of the form to a settings page.
04:14 Actually we don't really need that. We don't need any of this. Maybe we want to get the- URL of the form.
04:26 Hmm. Let's do with audit right now. Let's actually do without it for right now. Okay, save. We're just doing command s saving this.
04:39 Now what I'm going to do is I will refresh this page. So that our custom menu shows up. You must save.
04:48 If you do not save and you refresh it, then your app script is going to be unsaved. So we have this create form menu.
04:54 Let's see if this runs. We will need to do authorization the first time it runs. I do believe it might work the first time though.
05:02 We will see if it works or not. See the end result. Just approving the authorization. And I don't think it worked.
05:10 So let's do it again. Run the script. And we should have form responses here. Perfect. Finish the script. And it has your name, your email.
05:21 Let's look at it. I think we can see extensions. Manage form. It's already here. Edit form. See, we did not have to go up to tools.
05:33 Create form. We had to go up to our custom menu here. And it is correctly titled Simple Form. We have a text item.
05:47 That's probably not what we wanted. So we can edit. Let's edit that out. Let's go to extensions, app script. We have set title.
06:01 I wonder if we can, Just do this. Title of simple form. Actually, we don't need that at all. We need this set title.
06:17 Oh, this title we do not need at all. So wait, we just have a form. Set the title. The first time this form is used, the set destination, it's also going to set the title and set required login to false.
06:31 I'll explain this in a hot second. Let's delete this form. How you do that. If you have any mistakes in your form that's created, we have to go down here.
06:40 Unlink form. Click unlink. Then it will change this into a normal tab. We will delete this. It will also be in our drive.
06:52 You might want to move it to the trash. Might want to. Okay. Save all of this again. Let's try again.
06:59 We do not have to refresh it this time once we've edited some of that tech. Apps Script. Let's create that simple form.
07:06 See if this, it will say to form responses to. We can always edit this later. It's now asking your name and your email.
07:16 Let's go to tools, manage form, edit form. Great. We have a simple form title. We have your name. Does this work is the question and I know the answer is yes, but I want to show you why it's important that we have this set require login false.
07:39 Because when we're creating a form normally in settings. Responses and it will by default say restrict to users in my case.
07:50 I'm using better sheets workspace Google Workspace in your case. You'll have a different Google Workspace here. It'll say restrict users to this.
07:59 This will be on if you create a new form. You have to turn it off in order for public people without a login to sign, not have to sign in and fill out your form.
08:11 If you want to do an event, community event, anything like that. So we have to go in here and do this manually, but programmatically doing it is just this dot set require login false.
08:23 That is it. And doing that allows our form to be used by people who are not in our organization, which is great.
08:30 Which is wonderful. Most of the time we are using Google Sheets and Google Forms to gather data from people who do not have access to our Google Sheets and Google Forms.
08:40 So that's great. Hopefully this was helpful to get you started. On creating a form programmatically, there are lots of things available in this form app.
08:49 I'll show you in Google where is it? Switch my here it is. Google for developers. This is form app and it gives you a lot of options.
09:04 Of course, create the form, create checkbox validation, if you just want to checkbox instead of text. Actually, sorry, that's validation.
09:15 Set text item. Where is it? There it is, text item. And when you want to create a text item, it, where is it?
09:32 Set title, set required, set validation, form.add text item, set title, all sorts of things here that are at your disposal to programmatically create.
09:46 Why would you want to do this? Well, maybe I should have answered that in the beginning, but right now, really quickly I would say you want to create forms programmatically, especially if you're creating templates that you're selling, especially if you're creating lead magnets that you even give
09:59 away for free, but you want the ultimate user to create a form to gather information. You're doing, like, I don't know, a referral workflow, or you're trying to help someone else who's going to create a form, say, each week or each month, and it has to be a separate new form, but it has all the 
10:21 same information. It has all the same questions. It has the same order every single time and you want to create a brand new sheet, but you want all the same stuff in it meaning form, the form and the same questions, then creating it programmatically at the click of a button, like, literally
10:39 , for a user, one or two clicks, right very simple to set up. For other users who are having to do this on either a weekly daily basis, maybe they do, you have a couple webinars a day you run and you're like, I wish I had a feedback form at the end of this to just give a link and I don't have
11:01 to, like, get the drop down validation of which, for a which webinars did you show up to it's like, I want to create a brand new form for each and every webinar would be very useful for this kind of thing.
11:11 Alright, so hopefully this was helpful. And again, if you're a BetterSheets member, you're watching this on BetterSheets, just go down below, you can grab this create a form programmatically sheet, which already has the app script here written for you.
11:24 At least to get started. Thank you. Bye. Bye.