In one of my previous post I have showed you how you can create a simple Contact Us form with the help of Google Docs, this is one of easiest way to create forms for websites or blogs and more than that it’s very simple and literally anyone can create one.
But one problem with the form created like this is that you need to check back the form all the time to see if someone has entered/submitted something in that. Well this is a tough task and if you are someone who is frequently contacted it becomes really a hectic task. But there is way out for this and in this post I will explain how set an alert if someone submits a form and later I will tell you about a trick by which you can get all the form contents directly to email whenever someone submits a form.
How to set alert for the forms:
You can set an email alert for the forms so that whenever someone submits a form, you will get an instant alert on your email, follow the below steps to enable this feature.
- Open your Google Docs Forms.
- From the top click on Tools -> Notification rules.
- Now from the box select “a user submits a form” and “email right away”, and then select save.
- Once you have done this you will get email alerts whenever any user submits a form.
Get the form contents to email:
The above form notification settings is good, but there is one problem with this and that is you only get an alert about the form submit not the contents of it and in order to view contents inside form you still need to login to docs and view the file. Below trick which will fix this issue ,means you will be getting all the contents which a user has submitted right inside your email thus you don’t need to login to your forms again and again.
This is achieved by adding a code (thanks to Amit Agarwal), please follow the below steps.
- Open your Google Docs form.
- From the top click on Tools -> Scripts Editor...
- A windows will be opened where you need to paste the below code
function sendFormByEmail(e)
{
// Remember to replace XYZ with your own email address
var email = “XYZ”;
// Optional but change the following variable
// to have a custom subject for Google Docs emails
var subject = “Google Docs Form Submitted”;
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var message = “”;
for(var field in e.namedValues) {
message += field + ‘ :: ‘
+ e.namedValues[field].toString() + “\n\n”;
}
// This is the MailApp service of Google Apps Script
// that sends the email. You can also use GmailApp here.
MailApp.sendEmail(email, subject, message);
// Watch the following video for details
// http://youtu.be/z6klwUxRwQI
// By Amit Agarwal – www.labnol.org
}
- Please change the XYZ value to your email address where you want to receive the form contents. ( you have to authorize for the permission ,and this is only a one time process)
- Now open the Triggers from the same windows, and set the last field as on form submit and save the trigger.
- You can now do a test to see whether this is working by sending dummy form submits. You will see you have received an email which contains all the contents of the form which you have submitted.
The below video will explain more:
Note: Once you have set the content to email code, you will no longer require setting the notification on submit of form option(first trick). You can disable the same by going to your form and then Tools-Notification rules and deleting the notification. If you don’t do that you will receive 2 emails for every form submitted one from your set Notification rules and then from this set script code which is unnecessary so you can remove the first one which is no long required.
This original source of this article [VIA]: labnol.org .