MediaWiki:EventForm.js: Difference between revisions
Created page with "$(document).ready(function () { if (mw.config.get("wgPageName") === "Form:EventForm") { $("#pf-form").on("submit", function (event) { event.preventDefault(); // Stop default form submission var webhookUrl = "https://script.google.com/macros/s/EXAMPLE1234567890/exec"; // Replace with your Webhook URL var eventData = { eventDate: $("input[name='event_date']").val(), eventTime: $("input[name='..." |
No edit summary |
||
Line 1: | Line 1: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
var pageName = mw.config.get("wgPageName"); | |||
// Apply the script to the EventForm AND event pages (adjust namespace if needed) | |||
if (pageName.startsWith("Form:EventForm") || pageName.startsWith("Event:")) { | |||
$("#pf-form").on("submit", function (event) { | $("#pf-form").on("submit", function (event) { | ||
event.preventDefault(); | event.preventDefault(); | ||
var webhookUrl = "https://script.google.com/macros/s/ | var webhookUrl = "https://script.google.com/macros/s/YOUR_DEPLOYED_SCRIPT_ID/exec"; // Replace with yours | ||
var eventData = { | var eventData = { | ||
Line 11: | Line 14: | ||
eventLocation: $("input[name='event_location']").val(), | eventLocation: $("input[name='event_location']").val(), | ||
eventDescription: $("textarea[name='event_description']").val(), | eventDescription: $("textarea[name='event_description']").val(), | ||
submittedBy: mw.config.get("wgUserName") | submittedBy: mw.config.get("wgUserName") | ||
}; | }; | ||
console.log("Sending event data:", eventData); | |||
fetch(webhookUrl, { | fetch(webhookUrl, { | ||
Line 22: | Line 27: | ||
.then(data => { | .then(data => { | ||
console.log("Google Sheets Response:", data); | console.log("Google Sheets Response:", data); | ||
$("#pf-form").unbind("submit").submit(); | if (data.trim() === "Success") { | ||
$("#pf-form").unbind("submit").submit(); | |||
} else { | |||
alert("Submission failed: " + data); | |||
} | |||
}) | }) | ||
.catch(error => { | .catch(error => { | ||
console.error("Error:", error); | console.error("Error:", error); | ||
alert("Error submitting event. | alert("Error submitting event. Check console for details."); | ||
}); | }); | ||
}); | }); | ||
} | } | ||
}); | }); |
Revision as of 12:54, 9 March 2025
$(document).ready(function () { var pageName = mw.config.get("wgPageName"); // Apply the script to the EventForm AND event pages (adjust namespace if needed) if (pageName.startsWith("Form:EventForm") || pageName.startsWith("Event:")) { $("#pf-form").on("submit", function (event) { event.preventDefault(); var webhookUrl = "https://script.google.com/macros/s/YOUR_DEPLOYED_SCRIPT_ID/exec"; // Replace with yours var eventData = { eventDate: $("input[name='event_date']").val(), eventTime: $("input[name='event_time']").val(), eventLocation: $("input[name='event_location']").val(), eventDescription: $("textarea[name='event_description']").val(), submittedBy: mw.config.get("wgUserName") }; console.log("Sending event data:", eventData); fetch(webhookUrl, { method: "POST", body: JSON.stringify(eventData), headers: { "Content-Type": "application/json" } }) .then(response => response.text()) .then(data => { console.log("Google Sheets Response:", data); if (data.trim() === "Success") { $("#pf-form").unbind("submit").submit(); } else { alert("Submission failed: " + data); } }) .catch(error => { console.error("Error:", error); alert("Error submitting event. Check console for details."); }); }); } });