-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle-apps-script.gs
More file actions
37 lines (34 loc) · 1.41 KB
/
Copy pathgoogle-apps-script.gs
File metadata and controls
37 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* EditKaro.in — Google Apps Script backend
*
* SETUP
* 1. Create/open a Google Sheet.
* 2. Add two tabs (bottom of the sheet), named exactly:
* - "Subscribers" with header row: Timestamp | Email
* - "Contacts" with header row: Timestamp | Name | Email | Phone | Message
* 3. Extensions > Apps Script, delete any starter code, paste this file in.
* 4. Deploy > New deployment > type "Web app".
* - Execute as: Me
* - Who has access: Anyone
* 5. Copy the Web app URL and paste it into `scriptURL` in script.js
* (both forms already point at the same URL — this file routes them
* to the correct tab using the hidden "formType" field each form sends).
* 6. Re-deploy (Deploy > Manage deployments > Edit > New version) any time
* you change this file — editing it alone does not update the live URL.
*/
function doPost(e) {
const sheet = SpreadsheetApp.getActiveSpreadsheet();
const params = e.parameter;
const now = new Date();
if (params.formType === 'contact') {
const tab = sheet.getSheetByName('Contacts');
tab.appendRow([now, params.name, params.email, params.phone, params.message]);
} else {
// default: newsletter subscribe
const tab = sheet.getSheetByName('Subscribers');
tab.appendRow([now, params.email]);
}
return ContentService
.createTextOutput(JSON.stringify({ status: 'ok' }))
.setMimeType(ContentService.MimeType.JSON);
}