mountaineer03
New Coder
I am trying to do a honeypot script to delete submissions in google sheets. I don't know javascript that well but attempting this as a solution.
my header is as follows: Date, Name, Email, hidden field and message.
my sheet name is: leads
One last thing I don't see anything like GO LIVE or RUN script. Does it just auto save like all of the other google products.
So far it isn't working.
thanks
my header is as follows: Date, Name, Email, hidden field and message.
my sheet name is: leads
JavaScript:
function deleteSpamRows() {
// Get the sheet named "leads"
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("leads");
// Get all data from the sheet
var data = sheet.getDataRange().getValues();
// Array to store row numbers to delete
var rowsToDelete = [];
// Start from i = 1 to skip the header row (row 1)
for (var i = 1; i < data.length; i++) {
var row = data[i];
var honeypotValue = row[3]; // Column D (index 3) is the honeypot field
if (honeypotValue != "") {
rowsToDelete.push(i + 1); // Add the sheet row number (1-indexed)
}
}
// Delete rows from bottom to top to avoid shifting issues
for (var i = rowsToDelete.length - 1; i >= 0; i--) {
sheet.deleteRow(rowsToDelete[i]);
}
}
One last thing I don't see anything like GO LIVE or RUN script. Does it just auto save like all of the other google products.
So far it isn't working.
thanks