Skip to content

Instantly share code, notes, and snippets.

@moaalaa
Created May 4, 2024 18:39
Show Gist options
  • Save moaalaa/a43dc91dea620d015675ca3a07830e0c to your computer and use it in GitHub Desktop.
Save moaalaa/a43dc91dea620d015675ca3a07830e0c to your computer and use it in GitHub Desktop.
Add Form Fields to googe sheet using google App Scrpts
/*
Create A Google Sheet eand open it, From 'Extensions' Tab Choose Googe App Script
Put the following function in the app script and publish it as web app
*/
function doPost(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
var newRow = headers.map(function(header) {
return e.parameters[header] ? e.parameters[header].toString() : '';
});
sheet.appendRow(newRow);
}
<?php
namespace App\Http\Controllers;
use Http;
class HomeController extends Controller
{
use UsingSEO;
public function apply(Request $request)
{
Http::asForm()->post(
'https://script.google.com/macros/s/GOOGLE_APP_SCRIPT_ID/exec',
$request->only(['key1', 'key2']), // Same Keys must be in Google Sheet in first rows for sheet headers
);
session()->flash('success', trans('main.thanks_for_your_applied'));
return back();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment