2 Forms 1 Sheet
Learn how to use two forms in one Google Sheet and automate email notifications for form submissions using Google Apps Script.
So you want to use two forms in one sheet? Let's go first. Let's go and create our first form. We'll do a first event. We have this form here. We'll fill it out just to test it. And make sure we get form responses. There we go. We'll rename this first event. Now. If we wanna add a new one, create a new form. Let's go add questions. Second event, name an email. Let's go publish it. Anyone with the link publish ? Let's go. Make sure that one also works. Andy? two2@andy.com and there's our second one, so we could call the second event. In the tab name at the bottom, uh, let's go over to extensions and write some script to manage this. So what we're gonna do is we're gonna create a function here. And honestly, it could be anything. We'll say email, and I'm just gonna email myself, mail app.
Send an email form filled out, subject form filled, and we're gonna put a little special thing here, plus event do two. Spreadsheet app dot, get active spreadsheet , get active spreadsheet , get owner , get email. So we can put that all in A variable owner and we say form filled for event and we in the body say form filled. We want a variable here, event to fill that in. So let's say you have any other function here. This could be you close the, uh, close the form. You could email a report, you could do anything, copy any, anything you wanna do here, but we need to make sure we are getting the right. Uh, form that's being filled out. So there's some way to do that. So we're going to create a function that's on form, submit using the
trigger on form, submit, and it's gonna have some information here. So we'll call this form trigger , we'll call it E in this event. And we have some interesting stuff. So there are these things called installable triggers, and we're going to do on form submit . And this is the form submit objects. This is what we can get from a form submitted. We can know the named values , the range . We are going to have to get the URL of the form or the sheet that it's going to. So do variable sheet. Equals spreadsheet app, get active spreadsheet , get active sheet, get name, and then once we get that, the name of the sheet is the name of the event that we're active on. So we can do email sheet if we want or if there's some.
Connection. Maybe the sheet name is something different, but the event name is something else. You can change that here 'cause you get the sheet name . So let's save this and update the trigger . Actually, let's add the trigger . Go over the triggers on the left. Add trigger on the bottom right we're going to use form trigger . We're going to say event source. From a spreadsheet event type is on form change, or sorry, on form. Submit. Click save. Okay. We will have to allow it or authorize it. Now that trigger exists. So let's go and actually submit another response. For this first event, hit submit. Here's the email I got. I got form filled First event, so it filled in the name of the event, the first event based on in my sheet that it's on the first event. Isn't that cool? So now we know what sheet we're on. We can do a function here that says different things, right?
So let's say we wanna do it completely. Different message here for each event. Woo-hoo. And we wanna say, Hey, if it's a different event for second Event, oh no buggers. So how do we do that? Let me show you that right now. So. We have the event here. We know this event from this sheet is going to either be First Event or second Event. It'll be the text there. So you say, if event is equal to two equal signs first event, then we're gonna put some parentheses and put that email right inside there. Now thing is, you could say it's either gonna be first offender or second offender in this particular case. So we might put an else here, but I wanna show you a more sort of, more
interesting thing, which is we can just do this if again, but instead of the other email, we put this email right here and we say Second event. So again, this text is going to match the name. Of the tab that we're on, and we're getting that tab by this function here. Every form being submitted is running through this. It's gonna say, Hey, get, get me the sheet name , then go send an email. And so we're gonna get this in here, so let's save this and let's see if it's correct. Second event. Let's submit another response. Nicole is coming and we have an email that says Form filled, second Event. Oh, no buggers. So it got the information from the form. It said, Hey, I'm gonna put it on First Event or Second Event and I'm gonna do something different with it.
Awesome. Right. So if you're looking to do very specific things with App Script and you wanna do way more checkout, master spreadsheet automation,, it's a course I've put on Udemy i'll put a link in the description. And you can get this exact code in the description as well. I'll put the link to the sheet there. Copy it and check it out. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.