I want to build a JavaScript bookmarklet that can extract information from web pages and automatically send it to a Google Sheets through a Google Form. I’m having trouble getting the form submission to work properly.
Here’s what I’ve tried so far:
var submissionForm = document.createElement("form");
submissionForm.action = "https://docs.google.com/forms/d/e/1FAIpQLSc_example_form_id/formResponse";
submissionForm.method = "POST";
submissionForm.className = "auto-submit-form";
submissionForm.innerHTML = [
"<input id='field_1' name='entry.123456789' value='" + dateValue + "'/>",
"<input name='entry.987654321' value='" + userEmail + "'/>",
"<input name='entry.456789123' value='" + accountNumber + "'/>"
].join("");
submissionForm.submit();
console.log(submissionForm.innerHTML);
The problem is that nothing gets saved to the Google Sheet when I run this bookmarklet. I can’t see any network activity in the browser dev tools either. Is there a way to capture Google’s response or check if the submission worked?
I’m wondering if I should try a different approach using the viewform URL instead of formResponse. The actual form I’m trying to submit to is a standard Google Form. How can I programmatically fill out the form fields and submit them from my bookmarklet while staying on the original page that I’m parsing data from?