Index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Input Data</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
input, button { width: 100%; padding: 8px; margin: 5px 0; }
button { background: #1a73e8; color: white; border: none; }
</style>
</head>
<body>
<h3>Form Input Data Peserta</h3>
<input type="text" id="nama" placeholder="Nama Lengkap">
<input type="email" id="email" placeholder="Email">
<input type="text" id="asal" placeholder="Asal Sekolah">
<button onclick="kirimData()">Simpan</button>
<div id="result"></div>
<script>
function kirimData() {
var nama = document.getElementById('nama').value;
var email = document.getElementById('email').value;
var asal = document.getElementById('asal').value;
google.script.run
.withSuccessHandler(function(res) {
document.getElementById('result').innerText = res;
document.getElementById('nama').value = '';
document.getElementById('email').value = '';
document.getElementById('asal').value = '';
})
.simpanData(nama, email, asal);
}
</script>
</body>
</html>
Code.gs
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('index')
.setTitle('Form Input Data Sederhana');
}
function simpanData(nama, email, asal) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Data');
if (!sheet) {
sheet = ss.insertSheet('Data');
sheet.appendRow(['Timestamp', 'Nama', 'Email', 'Asal']);
}
sheet.appendRow([
new Date(),
nama,
email,
asal
]);
return 'Data berhasil disimpan';
}


Tidak ada komentar:
Posting Komentar