Google Form

Creating the Form

On Google Drive, create a Ticket Reservation form with all the necessary questions. You should ask for:

  • Last Name (required)
  • First Name
  • Email (required)
  • Performance Dates (required)
    • Drop down, include all the show dates and times as options
    • The question description should note "Reservations close 2 hours before each performance. Tickets may still be available at the door."
  • Number of Tickets (required)
    • Drop down, include from 1 to 9 tickets
    • The question description should note "For groups of 10 or more, email ensemble-request@mit.edu to arrange a group discount."
  • How did you hear about us?
    • Check boxes of options:
      • Newspaper/Tech
      • Posters
      • Word of Mouth
      • Emails
      • Other
  • Comments/Requests

In the form description at the top of the page, there should be a message including ticket prices and reservation details. Something like the following:

"Thank you for supporting the MIT Shakespeare Ensemble
All performances are in <La Sala de Puerto Rico (W20-202) on the second floor of the MIT Stratton Student Center (84 Massachusetts Ave) / Kresge Little Theater (W16-035) on MIT's campus (48 Massachusetts Ave)>.

Tickets prices are:
    $5 for MIT, Harvard, and Wellesley students
    $9 for MIT affiliates and other students
    $12 for general public

Payment for tickets is cash only and will be handled at the door on the day of the performance.

Reservations close for a show an hour before the show starts. You can still get tickets at the door!

A reservation will guarantee you admission as long as you arrive 15 minutes before the performance to claim it. Specific seating and other ticket sales are first come, first serve. We may need to give your ticket away if you arrive late.

<Any content warnings, the length of the show, etc.>"

The confirmation page should say something like the following:

Thank you for supporting the MIT Shakespeare Ensemble. Please arrive 15 minutes before the performance to claim your reservation.
If you would like to help usher or house manage, please email XXX-request@mit.edu. Thank you!

A good example of a form (which can be directly copied if desired) can be found here: https://drive.google.com/open?id=1Ey9HKsAqHZLOnu5V-hgcF6clvR6k53n2Tx2f_fbk6QE

Setting Up the Email Confirmations

Set up a spreadsheet for the form responses. While in the spreadsheet, go to the "Tools" menu and select "Script Editor". This will open a new page where you can enter Google scripts code. Delete any code that Google automatically has typed, and past the following into the document:

function SendConfirmationMail(e) {    // e is an event object that is defined by the event of form submission. Contains submission info. 
     var ss, bcc, sendername, subject, headers, ptest;
     var message, value, textbody, sendto;
     bcc = "ensemble-tickets@mit.edu";
     sendername = "MIT Shakespeare Ensemble";
     subject = "EXAMPLE Ticket Reservation Confirmation";
     message = "We have received your ticket reservation.<br>Thank you!<br>Please arrive to pick up your reservation at least 15 minutes before performance time.<br>The performance will be in La Sala de Puerto Rico (W20-202), on the second floor of the MIT Stratton Student Center at 84 Massachusetts Ave.<br><br>";
     ss = SpreadsheetApp.getActiveSheet();
     headers = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];                      // Creates an array of the column headers.
 
     ptest = ss.getRange(ss.getLastRow(), 1, 1, ss.getLastColumn()).getValues()[0];          // Gets the last row from the spreadsheet. Will be used instead of e.
     Logger.log(headers);                                                                    // Adds headers to log. Note that the log is not actually used for anything :P
     Logger.log(ptest);
//     Logger.log(e);   // Adds event object in its entirety to the log.
//     sendto = e.namedValues['Email Address'][0];   // Pulls the email address from the event object.
  sendto = ptest[headers.indexOf('Email Address:')]                                        // Pulls the email address by finding the index within headers. Make sure the name of the header here exactly matches what it is on the form or it won't work!
     for (var i in headers) {                                                                // For every key in headers
//       value = e.namedValues[headers[i]][0].toString();   // Gets the value corresponding to a specific header from the event object. Makes it a string. This line is hard for a human to read.
       value = ptest[i].toString()                                                           // Gets the value corresponding to a specific header.
       Logger.log(value);                                                                    // Adds this value (such as "Peter" for "First Name") to the log.
       if ((i !== "0") && (value !== "")) {                                                  // If this is not the Timestamp && the form field was not left blank.
           message += headers[i] + ' :: ' + value + "<br>";                                  // Add the header, a little space, the form input value, and then a line break.
       }
     }
     textbody = message.replace("<br>", "\n");                                               // This changes the HTML line break character to the text interpreter line space character.
     GmailApp.sendEmail(sendto, subject, textbody,                                           // Sends an email to the person who filled out the form, with a previously defined subject and body.
                        {bcc: bcc, name: sendername, htmlBody: message, replyTo: bcc});      // This is an optional field. Adds bcc to us and changes the name of the sender. htmlBody makes it so that devices capable of rendering HTML will render that instead. replyTo sets the default reply-to address, us.
}

// [end of code]

The following will have to be done while logged into the Shakespeare Ensemble Google account. If you don't have access, contact the Officers to do this for you.

The above code essentially takes an event (that will be the form submission) and sends an email confirmation based on the information in the form. However, the thing that triggers the script (the form submission) has not yet been defined. While in the script editor, go to the "Edit" menu and select "Current project's triggers". This should open a window that says "No results" in the middle. Click on the "+ Add Trigger" button in the lower right hand corner, and create a trigger with the following properties:

  • Under "Choose which function to run" select "SendConfirmationMail" (this should already be selected by default, but double-check just to be sure)
  • Under "Choose which deployment should run" select "Head" (again, this should be selected by default)
  • Under "Select event source" select "From spreadsheet" (again, this should be selected by default)
  • Under "Select event type" select "On form submit"
  • Under "Failure notification settings" select "Notify me immediately"

Leave all other fields the same.

Press "Save," then grant the script whatever access to the Ensemble Account that it asks for. Now the trigger should be set up, even if your browser tells you that the app is unverified and potentially unsafe.

Update ensemble-tickets@mit.edu

The last thing you need to do before testing the form is update the ensemble-tickets@mit.edu mailing list to have ensemble-request@mit.edu and the current show request list. Please change this before testing the form, otherwise people on the previous show's mailing list will get lots of unnecessary emails.

Testing the Confirmation emails

Now comes the fun time where you can debug the form (hopefully it won't take much) while simultaneously spamming the members of ensemble-tickets@ with clever comments and made-up names. Test as much as needed/desired.

Embedding the Form in the Website

Have the webmaster or an officer or anyone on ensemble-webmaster@mit.edu do the following for you.

In the Google form, click "Send Form", then press "Embed" to get the html. The height and width can be adjusted later, so don't worry about that.

Now open the Ensemble Locker, and go to web_scripts > tickets > index.php. Under the comment "<!-- EMBED LINK TO GOOGLE FORM BELOW THIS -->", paste the html from Google forms. Be sure to delete the embedding html from the previous show reservations. Set the width to 84% and the height to 1250px (or whatever looks good).

That's it! Go to ensemble.mit.edu/tickets, and you should see the ticket form live!

 

 

  • No labels