aku minta chat gpt lagi untuk buatkan kodenya, agar pembaca bisa meninggalkan pesan dan kesan mereka terhadap website ini.
<div style="padding:20px; border-radius:15px; background:#8e302f; max-width:500px; margin:auto; color:white; font-family:Arial, sans-serif;">
<h2 style="text-align:center; margin-bottom:15px; color:white;">Community Love ♡</h2>
<input type="text" id="name" placeholder="Your Name"
style="width:100%; padding:10px; border:none; border-radius:8px; margin-bottom:10px; font-size:1rem;" required>
<textarea id="message" rows="4" placeholder="Your Message..."
style="width:100%; padding:10px; border:none; border-radius:8px; margin-bottom:10px; font-size:1rem;" required></textarea>
<div style="margin-bottom:10px; font-size:1.5rem; color:#ccc;" id="starRating">
<span onclick="setRating(1)">★</span>
<span onclick="setRating(2)">★</span>
<span onclick="setRating(3)">★</span>
<span onclick="setRating(4)">★</span>
<span onclick="setRating(5)">★</span>
</div>
<button onclick="submitForm()"
style="background:white; color:#8e302f; padding:10px 20px; font-size:1rem; font-weight:bold; border:none; border-radius:8px; cursor:pointer;">
Submit
</button>
</div>
<div id="testimonialList" style="margin-top:30px;"></div>
<script>
let selectedRating = 0;
function setRating(val) {
selectedRating = val;
let stars = document.querySelectorAll("#starRating span");
stars.forEach((s, i) => {
s.style.color = (i < val) ? "gold" : "#ccc";
});
}
function submitForm() {
let name = document.getElementById("name").value;
let message = document.getElementById("message").value;
if (!name || !message || selectedRating === 0) {
alert("Please fill all fields and rating!");
return;
}
fetch("https://script.google.com/macros/s/AKfycbxxNoyNSuPRvTQwL5bj2_AVpDbn1H6Amn63D_azOsKoL4H1UBkVLykZ_p7LGHvLJtv5aw/exec", {
method: "POST",
contentType: "application/json",
body: JSON.stringify({ name, message, rating: selectedRating })
})
.then(res => res.json())
.then(() => {
alert("Thanks for your feedback!");
loadTestimonials(); // Refresh testimonial list
});
}
function loadTestimonials() {
fetch("https://script.google.com/macros/s/AKfycbxxNoyNSuPRvTQwL5bj2_AVpDbn1H6Amn63D_azOsKoL4H1UBkVLykZ_p7LGHvLJtv5aw/exec")
.then(res => res.json())
.then(data => {
let container = document.getElementById("testimonialList");
container.innerHTML = "";
data.reverse().forEach(t => {
let div = document.createElement("div");
div.style.background = "#8e302f";
div.style.color = "white";
div.style.padding = "15px";
div.style.borderRadius = "12px";
div.style.marginBottom = "10px";
div.innerHTML = `
<p>"${t.message}"</p>
<p style="color:gold;">${"★".repeat(t.rating)}${"☆".repeat(5-t.rating)}</p>
<p><strong>@${t.name}</strong></p>
`;
container.appendChild(div);
});
});
}
loadTestimonials();
</script>
buka Google Sheets
masukkan header kolom dengan nama, massage, rating
lalu pilih menu extensions
pilih apps scrip
lalu masukkan kode dari chat gpt
function doPost(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = JSON.parse(e.postData.contents);
// Simpan data ke sheet
sheet.appendRow([data.name, data.message, data.rating, new Date()]);
return ContentService.createTextOutput(
JSON.stringify({ result: "success" })
).setMimeType(ContentService.MimeType.JSON);
}
function doGet(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues();
var result = [];
for (var i = 1; i < data.length; i++) {
result.push({
name: data[i][0],
message: data[i][1],
rating: data[i][2],
date: data[i][3],
});
}
return ContentService.createTextOutput(
JSON.stringify(result)
).setMimeType(ContentService.MimeType.JSON);
}
6. klik deploy dan pilih new deployment
7. pilih web app dan ganti who has access menjadi anyone
8. klik authorize access
9. klik allow
10. copy link web app nya ke dalam code dari chat gpt
<div style="max-width:400px;margin:auto;background:#822e2e;padding:20px;border-radius:15px;color:white;">
<h2 style="text-align:center;">Community Love ♡</h2>
<input type="text" id="name" placeholder="Your Name" style="width:100%;padding:10px;margin:10px 0;border-radius:8px;border:none;">
<textarea id="message" placeholder="Your Message..." style="width:100%;padding:10px;margin:10px 0;border-radius:8px;border:none;"></textarea>
<div style="margin:10px 0;">
<span onclick="setRating(1)">★</span>
<span onclick="setRating(2)">★</span>
<span onclick="setRating(3)">★</span>
<span onclick="setRating(4)">★</span>
<span onclick="setRating(5)">★</span>
</div>
<button onclick="submitForm()" style="background:white;color:#822e2e;padding:10px 20px;border:none;border-radius:8px;font-weight:bold;cursor:pointer;">
Submit
</button>
</div>
<script>
let rating = 0;
function setRating(val) { rating = val; }
function submitForm() {
const name = document.getElementById("name").value;
const message = document.getElementById("message").value;
fetch("PASTE_LINK_EXEC_DISINI", {
method: "POST",
body: JSON.stringify({ name, message, rating }),
headers: { "Content-Type": "application/json" }
})
.then(res => res.json())
.then(res => {
if(res.result === "success") {
alert("Thank you! Your message was submitted.");
document.getElementById("name").value = "";
document.getElementById("message").value = "";
}
})
.catch(err => alert("Error: " + err));
}
</script>
ganti PASTE_LINK_EXEC_DISINI dengan link dari google sheets tadi. lalu masukkan ke embed di google sites. jadi dehh !!!!