Seeking help with customizing HTML output from a Google Apps Script form to have different styles for email and PDF files.
Current code:
function doGet(request) {
return HtmlService.createTemplateFromFile('index')
.evaluate();//not all caps but it has to match the name of the file and it doesn't - Change to PAGE
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
/****** SHEET ****/
function userClicked(userInfo){
var url = "https://docs.google.com/spreadsheets/your-sheet-ID";
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Data");
ws.appendRow([userInfo.name, userInfo.email, userInfo.comment, new Date()]);
}
function submitData(form) {
var subject='New Feedback';
var body=Utilities.formatString('name: %s <br />email: %s<br />Comment: %s', form.name,form.email,form.comment);
/*** FOR HTML EMAIL ***/
var htmlTemplate = HtmlService.createTemplateFromFile("PDF-page.html");
htmlTemplate.name = form.name;
htmlTemplate.email = form.email;
var htmlBody = htmlTemplate.evaluate().getContent();
/*** CREATE PDF ***/
var folderId = "your-folder-ID"; // Please set the folder ID. // Added
var blob = Utilities.newBlob(htmlBody, MimeType.HTML, form.name).getAs(MimeType.PDF); // Added - PDF from html email - comment line for serve PDF from document template
var file = DriveApp.getFolderById(folderId).createFile(blob); // Added
//****email****//
var aliases = GmailApp.getAliases()
Logger.log(aliases); //returns the list of aliases you own
Logger.log(aliases[0]);
...
For more information about this application, check out my post here:
Google App Script setTimeout Function problem
The following two sections illustrate different styles:
The first section uses the Gmail basic style, specifying the fields edited in the form:
Name: example name
Email: example email
Comment: example comment
var body=Utilities.formatString('name: %s <br />email: %s<br />Comment: %s', form.name,form.email,form.comment);
/****************************************************************************/
GmailApp.sendEmail(...)
The second section defines the page style using a separate HTML file ("PDF-page.html"):
var htmlTemplate = HtmlService.createTemplateFromFile("PDF-page.html");
htmlTemplate.name = form.name;
htmlTemplate.email = form.email;
var htmlBody = htmlTemplate.evaluate().getContent();
I hope this explanation clarifies the script adjustments made. If you need further assistance, feel free to ask. Thank you!
...