Spaces:
Running
Running
File size: 1,344 Bytes
488c39e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <?php
// Process form submission and save to Google Sheets
require_once __DIR__ . '/vendor/autoload.php'; // Include Google API client
// Get form data
$child = isset($_POST['child']) ? $_POST['child'] : '';
$option = isset($_POST['option']) ? $_POST['option'] : '';
$additional = isset($_POST['additional']) ? intval($_POST['additional']) : 0;
$comments = isset($_POST['comments']) ? $_POST['comments'] : '';
$total = isset($_POST['total']) ? $_POST['total'] : '0';
$timestamp = date('Y-m-d H:i:s');
// Configure Google Sheets API
$client = new Google_Client();
$client->setApplicationName('Christmas Photos');
$client->setScopes([Google_Service_Sheets::SPREADSHEETS]);
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$service = new Google_Service_Sheets($client);
$spreadsheetId = 'YOUR_SPREADSHEET_ID';
$range = 'Sheet1!A2:E';
// Prepare data
$values = [
[$child, $option, $additional, $total, $comments, $timestamp]
];
$body = new Google_Service_Sheets_ValueRange([
'values' => $values
]);
$params = [
'valueInputOption' => 'RAW'
];
// Insert data
$result = $service->spreadsheets_values->append($spreadsheetId, $range, $body, $params);
// Return response
header('Content-Type: application/json');
echo json_encode([
'success' => true,
'message' => 'Data saved successfully'
]);
?> |