Last active
August 29, 2015 14:06
-
-
Save kcmckell/73e9907249a638209a68 to your computer and use it in GitHub Desktop.
Hopu Confirmation Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onFormSubmit(e) { | |
// Initial Testing/Debugging | |
// var test = ''; | |
// var appendme = ''; | |
// for (var i = 0; i<e.values.length; i++) { | |
// appendme = i+': '+e.values[i]; | |
// Logger.log(appendme); | |
// test += appendme+'\n'; | |
// } | |
Logger.log(e); | |
MailApp.sendEmail('kcmckell@gmail.com','Form feedback',Logger.getLog()); | |
var timestamp = e.values[0]; | |
var player_bool = e.values[1] == 'Player'; | |
var team, abilities, name, gender, email, phone, emergency, food, camping, hoputeer, paymentmethod, shirt, waiver, sponsor; | |
if (player_bool) { | |
team = e.values[4]; | |
abilities = { | |
throwing: e.values[5], | |
fitness: e.values[6], | |
knowledge: e.values[7], | |
experience: e.values[8] | |
}; | |
} else { | |
sponsor = { | |
team: e.values[2], | |
name: e.values[3] | |
}; | |
}; | |
name = { | |
first: e.values[9], | |
last: e.values[10] | |
}; | |
gender = e.values[11]; | |
email = e.values[13]; | |
phone = e.values[14]; | |
emergency = { | |
name: e.values[15], | |
phone: e.values[16] | |
}; | |
food = e.values[17]; | |
camping = e.values[18]; | |
hoputeer = e.values[19]; | |
paymentmethod = e.values[22]; | |
shirt = e.values[20]; | |
waiver = e.values[21]; | |
// Conditional text strings. | |
var paymentprompt = { | |
"PayPal" : "Please proceed to the [online payment page](http://hopukalewa.com/individual_pay.php) to complete your registration.", | |
"teambid" : "You've indicated that your fee was included with the team bid. We'll check with your team captain and let you know if there are any discrepancies.", | |
"Cash" : "Please be sure to bring $180 with you to the fields when you arrive. Checks and credit cards -*will not be accepted*- at the fields.", | |
"HULAship" : "Congratulations on your HULAship! If there is any balance due, please bring it to any committee member as soon as you can. Mahalo!", | |
"other" : "Please get in touch with the [Tournament Directors](mailto:\"hoputd@hawaiiultimate.com\") as soon as possible to sort out your registration fee." | |
}; | |
// Generate email. | |
var subject = "Hopu Ka Lewa 16 registration confirmation"; | |
var body = "Thank you for your registration on " + timestamp + ".\n\n"; | |
if (paymentprompt.hasOwnProperty(paymentmethod)) { body += paymentprompt[paymentmethod]; } | |
else if (paymentmethod.indexOf("team bid") >= 0) { body += paymentprompt["teambid"]; } | |
else if (paymentmethod.indexOf("Cash") >= 0) { body += paymentprompt["Cash"]; } | |
else if (paymentmethod.indexOf("HULAship") >= 0) { body += paymentprompt["HULAship"]; } | |
else if (paymentmethod.indexOf("Other") >= 0) {body += paymentprompt["other"]; } | |
body += "\n\n"; | |
body += "We received the following registration information. If there are any discrepancies, please contact the [Tournament Directors](mailto:hoputd@hawaiiultimate.com).\n" | |
body += "\nName: " + name.first + " " + name.last; | |
if (player_bool) { | |
body += "\nTeam: " + team; | |
} else { | |
body += "\nSponsor: " + sponsor.name + " on " + sponsor.team; | |
} | |
body += "\nGender: " + gender; | |
body += "\nEmail: " + email; | |
body += "\nPhone: " + phone; | |
body += "\nEmergency contact: " + emergency.name + " at " + emergency.phone; | |
body += "\nFood preference: " + food; | |
body += "\nCamping preference: " + camping; | |
body += "\nHoputeer preference: " + hoputeer; | |
body += "\nShirt size: " + shirt; | |
body += "\n\nAgain, please follow through with your payment method of choice as soon as possible."; | |
body += "\n\nWe're looking forward to seeing you in Waimanalo!"; | |
body += "\n\nAloha,\nStacey and J-Dub, 2014 Hopu Ka Lewa Tournament Directors"; | |
// From the plaintext email body, make a pretty HTML email body. | |
var htmlbody = body.replace("\n","<br/>"); | |
htmlbody = htmlbody.replace("-*","<strong>"); | |
htmlbody = htmlbody.replace("*-","</strong>"); | |
// Sweet REGEX for Markdown-to-HTML from here: https://gist.github.com/jbroadway/2836900 (adapted from PHP to JavaScript). | |
htmlbody = htmlbody.replace(/\[([^\[]+)\]\(([^\)]+)\)/,'<a href=\"$2\">$1</a>'); | |
// Send the email. | |
var optAdvancedArgs = { | |
name : "Hopu Ka Lewa 16", | |
//htmlBody : htmlbody, | |
replyTo: "hoputd@hawaiiultimate.com" | |
}; | |
MailApp.sendEmail(email, subject, body, optAdvancedArgs); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onFormSubmit(e) { | |
// Initial Testing/Debugging | |
// var test = ''; | |
// var appendme = ''; | |
// for (var i = 0; i<e.values.length; i++) { | |
// appendme = i+': '+e.values[i]; | |
// Logger.log(appendme); | |
// test += appendme+'\n'; | |
// } | |
Logger.log(e); | |
MailApp.sendEmail('kcmckell@gmail.com','Form feedback',Logger.getLog()); | |
var timestamp = e.values[0]; | |
var player_bool = e.values[1] == 'Player'; | |
var team, abilities, name, gender, email, phone, emergency, food, camping, hoputeer, paymentmethod, shirt, waiver, sponsor; | |
if (player_bool) { | |
team = e.values[2]; | |
abilities = { | |
throwing: e.values[3], | |
fitness: e.values[4], | |
knowledge: e.values[5], | |
experience: e.values[6] | |
}; | |
name = { | |
first: e.values[7], | |
last: e.values[8] | |
}; | |
gender = e.values[9]; | |
email = e.values[11]; | |
phone = e.values[12]; | |
emergency = { | |
name: e.values[13], | |
phone: e.values[14] | |
}; | |
food = e.values[15]; | |
camping = e.values[16]; | |
hoputeer = e.values[17]; | |
paymentmethod = e.values[20]; | |
shirt = e.values[18]; | |
waiver = e.values[19]; | |
} else { | |
sponsor = { | |
team: e.values[2], | |
name: e.values[3] | |
}; | |
name = { | |
first: e.values[4], | |
last: e.values[5] | |
}; | |
gender = e.values[6]; | |
email = e.values[8]; | |
phone = e.values[9]; | |
emergency = { | |
name: e.values[10], | |
phone: e.values[11] | |
}; | |
food = e.values[12]; | |
camping = e.values[13]; | |
hoputeer = e.values[14]; | |
paymentmethod = e.values[17]; | |
shirt = e.values[15]; | |
waiver = e.values[16]; | |
}; | |
// Conditional text strings. | |
var paymentprompt = { | |
"PayPal" : "Please proceed to the [online payment page](http://hopukalewa.com/individual_pay.php) to complete your registration.", | |
"teambid" : "You've indicated that your fee was included with the team bid. We'll check with your team captain and let you know if there are any discrepancies.", | |
"Cash" : "Please be sure to bring $180 with you to the fields when you arrive. Checks and credit cards -*will not be accepted*- at the fields.", | |
"HULAship" : "Congratulations on your HULAship! If there is any balance due, please bring it to any committee member as soon as you can. Mahalo!", | |
"other" : "Please get in touch with the [Tournament Directors](mailto:\"hoputd@hawaiiultimate.com\") as soon as possible to sort out your registration fee." | |
}; | |
// Generate email. | |
var subject = "Hopu Ka Lewa 16 registration confirmation"; | |
var body = "Thank you for your registration on " + timestamp + ".\n\n"; | |
if (paymentprompt.hasOwnProperty(paymentmethod)) { body += paymentprompt[paymentmethod]; } | |
else if (paymentmethod.indexOf("team bid") >= 0) { body += paymentprompt["teambid"]; } | |
else if (paymentmethod.indexOf("Cash") >= 0) { body += paymentprompt["Cash"]; } | |
else if (paymentmethod.indexOf("HULAship") >= 0) { body += paymentprompt["HULAship"]; } | |
else if (paymentmethod.indexOf("Other") >= 0) {body += paymentprompt["other"]; } | |
body += "\n\n"; | |
body += "We received the following registration information. If there are any discrepancies, please contact the [Tournament Directors](mailto:hoputd@hawaiiultimate.com).\n" | |
body += "\nName: " + name.first + " " + name.last; | |
if (player_bool) { | |
body += "\nTeam: " + team; | |
} else { | |
body += "\nSponsor: " + sponsor.name + " on " + sponsor.team; | |
} | |
body += "\nGender: " + gender; | |
body += "\nEmail: " + email; | |
body += "\nPhone: " + phone; | |
body += "\nEmergency contact: " + emergency.name + " at " + emergency.phone; | |
body += "\nFood preference: " + food; | |
body += "\nCamping preference: " + camping; | |
body += "\nHoputeer preference: " + hoputeer; | |
body += "\nShirt size: " + shirt; | |
body += "\n\nAgain, please follow through with your payment method of choice as soon as possible."; | |
body += "\n\nWe're looking forward to seeing you in Waimanalo!"; | |
body += "\n\nAloha,\nStacey and J-Dub, 2014 Hopu Ka Lewa Tournament Directors"; | |
// From the plaintext email body, make a pretty HTML email body. | |
var htmlbody = body.replace("\n","<br/>"); | |
htmlbody = htmlbody.replace("-*","<strong>"); | |
htmlbody = htmlbody.replace("*-","</strong>"); | |
// Sweet REGEX for Markdown-to-HTML from here: https://gist.github.com/jbroadway/2836900 (adapted from PHP to JavaScript). | |
htmlbody = htmlbody.replace(/\[([^\[]+)\]\(([^\)]+)\)/,'<a href=\"$2\">$1</a>'); | |
// Send the email. | |
var optAdvancedArgs = { | |
name : "Hopu Ka Lewa 16", | |
//htmlBody : htmlbody, | |
replyTo: "hoputd@hawaiiultimate.com" | |
}; | |
MailApp.sendEmail(email, subject, body, optAdvancedArgs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes the blank entries in the different classes of registrations get treated differently. Most recently (v1), all fields have the same numbering (but Players have different fields present than Guests).
Before (v0), the numbering was different for Players vs Guests.