undefined / submit.php
srampytlik's picture
I have web pages supported with php. I need to create a form so that it has the same layout for 200 participants, but with specific set of 2 images (christmas photo of a child typically for parents and grandparents) for each user. Each anonymized user will receive specific link to the form via a unique QR code (use php to identify the user based on the link used in the QR code). The user will select one of the two presented pictures of his/her child and optionally enter number of additional photos. Each option has specific price.
488c39e verified
Raw History Blame Contribute Delete
1.34 kB
<?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'
]);
?>