MediaWiki:EventForm.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
$(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.");
});
});
}
});