Data doesn't get saved
Hey, I'm trying to use this tool to keep contact of my clients but the data doesn't appear to be saved.
I'm getting Email and a new row get created in the sheet but the data is empty
here is my code
handleSubmit https://codefile.io/f/YPUx90dlz7
function doPost(req) { FormEasy.setEmail('{myemail}@gmail.com'); FormEasy.setRecaptcha(_MY_SECRET_KEY) FormEasy.setFields('firstName', 'lastName', 'phone') return FormEasy.action(req); }
Looks like the field names are mismatched.
Try to deploy this again with the right field names and use the latest deployed URL for sending requests and that should solve the problem
function doPost(req) {
FormEasy.setEmail('{myemail}@gmail.com');
FormEasy.setRecaptcha(_MY_SECRET_KEY);
FormEasy.setFields('firstName', 'lastName', 'phone');
return FormEasy.action(req);
}
did you ever get it fixed because its also not working for me...
It works great for me. I'm a regular user of it.
Try this demo code and check it out with your URL: https://stackblitz.com/edit/js-55dzc8?file=index.html,index.js
app script function doPost(req) { FormEasy.setEmail('[email protected]');
FormEasy.setRecaptcha('----------------------------');
FormEasy.setFields('Fname', 'Lname', 'email', 'phone', 'message', 'reference', 'date');
return FormEasy.action(req); }
// Function to handle form submission document.getElementById('contact-form').addEventListener('submit', function (event) {
const data = {
Fname: document.getElementById('Fname').value
Lname: document.getElementById('Lname').value,
email: document.getElementById('email').value,
phone: document.getElementById('phone').value,
message: document.getElementById('message').value,
date: new Date().toISOString(),
};
const url = 'https://script.google.com/macros/s/AKfycbyuYpO5tK4_mry_4SRcU8gPXQYYFncd92zsZF4F52H3NJKgs4HDGXw0wUHgtSnWsASO/exec';
// Make the fetch request to send the form data to Google Apps Script
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'text/plain;charset=utf-8/'
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((data) => {
console.log('Form submitted successfully:', data);
alert('Form submitted successfully!');
})
.catch((err) => {
console.log('Error submitting form:', err);
alert('There was an error submitting the form.');
});
});
//html
Send me a message!
Looks like this is missing for recaptcha:
const data = {
// ...
gCaptchaResponse: document.getElementById('g-recaptcha-response').value,
};
yes but im still having issues, mostly with google script, this is whats on there: function doPost(req) { FormEasy.setEmail('[email protected]'); FormEasy.setRecaptcha('------------------------'); FormEasy.setFields('Fname', 'Lname', 'email', 'website', 'message'); return FormEasy.action(req); }
the JS is :
// Function to handle form submission document.getElementById('contact-form').addEventListener('submit', function (event) { event.preventDefault(); // Prevent the default form submission behavior
const captcha= grecaptcha.getResponse();
if (!captcha) {
alert('Please complete the CAPTCHA');
return;
}
const data = {
Fname: document.getElementById('Fname').value,
Lname: document.getElementById('Lname').value,
email: document.getElementById('email').value,
phone: document.getElementById('phone').value,
message: document.getElementById('message').value,
date: new Date().toISOString(),
gCaptchaResponse: document.getElementById('g-recaptcha-response').value,
};
const url = 'https://script.google.com/macros/s/AKfycbx8a7yV7CVl-XOQsNX5wRh9ErMpaMks67Zu-_l2ZK5FekcuH0TvYJxGkU-giUgE5CBnfw/exec';
// Make the fetch request to send the form data to Google Apps Script
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((data) => {
console.log('Form submitted successfully:', data);
alert('Form submitted successfully!');
// Reset the form fields
document.getElementById('contact-form').reset();
captcha.reset();
})
.catch((err) => {
console.log('Error submitting form:', err);
alert('There was an error submitting the form.');
});
});
its not even saying im a user on the google script and im having CORS issues as well.
i finally got it to work...