Hello Guys,
Today Im showing you to how to Send Google form data same time when user submit the form. For now google just able to send mail as well as Add data into relevant connected google Excel sheet.
Now let’s go step by step for what we need to do if we need to pass data to the other server when submit google form data.
Step 1:
On first step you need to create a form if you have not then. for that go to Forms and click on + icon to create a new form.
Now after creating a form you need to click on second tab as responses. once you click you will see below details.
Now click on Google sheet icon
Above one is for setup a google form and form data responses google sheet
Step 2:
In step 2 we are going to see how we can send data to other server.
So in last step you have created or open existing attach google sheet with this form.
After creating a sheet you need to create a Google Script. by clicking then Tools > Script Editor. When you click you will see below screen
First you need to change this Script project name and save. then we will going to write event function.
More events and info you can find from here.
https://developers.google.com/apps-script/understanding_events
Now we going to add onSubmit function and that will execute when we submit the form.
/**
* A trigger-driven function that sends out calendar invitations and a
* personalized Google Docs itinerary after a user responds to the form.
*
* @param {Object} e The event parameter for form submission to a spreadsheet;
* see https://developers.google.com/apps-script/understanding_events
*/
function onFormSubmit(e) {
var url = "https://9code.info/gscript.php"; //Here is your liknk
var data =
{
"timestamp" : e.namedValues['Timestamp'][0],
"email" : e.namedValues['Email'][0],
"name" : e.namedValues['Name'][0],
"phoneNo" : e.namedValues['Mobile Number'][0],
};
//above is all fields with name
var options =
{
"method" : "POST",
"payload" : data,
"followRedirects" : false,
"muteHttpExceptions": false
};
var result = UrlFetchApp.fetch(url, options);
//sending data to our server
if (result.getResponseCode() == 200) {
Logger.log(payload);
Logger.log(result);
}
Okay the above function is used for send data to other server when submit the google form.
Step 3:
You thing why this is third step but this is the important step to trigger event otherwise meaningless above script code.
So for setup trigger you need to go Edit > Current Project Triggers
When you click on that you will see other screen and then you need to click on Add Trigger button.
You need to carefully select above option same as what we selected on above screen.
Now all done and when you submit the google form that will send data to you added URL with data.
Let me know if you like to do further development or questions you can send me message or write comment below.
Thank you so much 🙂
Antonello says
Hi,i’ve just read yourt article http://9code.info/google-form/ and I’d like to thanl you a lot.
I sent data by adding
“contentType” : “application/json”,
“payload” : JSON.stringify(data);
Could you please tell me how to read data fom php?
I cant use $_POST directly.
neither json_decode( $_GET[“payload”] );
Could you please help me?
Thankyou
Parbat Pithiya says
You are welcome,
You can get all post data by using:
$post = file_get_contents(‘php://input’);
echo “
“;
If you are not able get from $_POST
Let me know if you are using other language or other way you get data or having any issue
thanks