Ig0tU commited on
Commit
67fe0fc
·
1 Parent(s): bac09d2

Route form submissions to specific Google Sheet tabs based on origin URL

Browse files
Files changed (1) hide show
  1. server.js +10 -3
server.js CHANGED
@@ -103,9 +103,16 @@ app.post('/api/submit', async (req, res) => {
103
  // We are going to append to Columns A to G (Timestamp, Name, Email, Message, Phone, Subject, Origin).
104
  const TIMESTAMP = new Date().toISOString();
105
 
106
- // The range specifies where to append. A simple 'Sheet1' usually works,
107
- // or just the spreadsheet name. Let's use 'Sheet1!A:G' or just 'A:G'
108
- const range = 'Sheet1'; // Default sheet name in most English locales
 
 
 
 
 
 
 
109
 
110
  const response = await sheets.spreadsheets.values.append({
111
  spreadsheetId,
 
103
  // We are going to append to Columns A to G (Timestamp, Name, Email, Message, Phone, Subject, Origin).
104
  const TIMESTAMP = new Date().toISOString();
105
 
106
+ // The range specifies where to append.
107
+ // Dynamically sort into different tabs based on the origin URL!
108
+ let range = 'Sheet1';
109
+ if (origin) {
110
+ const lowerOrigin = origin.toLowerCase();
111
+ if (lowerOrigin.includes('contact')) range = 'Contact';
112
+ else if (lowerOrigin.includes('tours')) range = 'Tours';
113
+ else if (lowerOrigin.includes('escort')) range = 'Escort';
114
+ else if (lowerOrigin.includes('honor')) range = 'Honor';
115
+ }
116
 
117
  const response = await sheets.spreadsheets.values.append({
118
  spreadsheetId,