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 () { 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='event_time']").val(), eventLocation: $("input[name='event_location']").val(), eventDescription: $("textarea[name='event_description']").val(), submittedBy: mw.config.get("wgUserName") // Get the logged-in user's wiki username }; 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); $("#pf-form").unbind("submit").submit(); // Allow form submission after webhook }) .catch(error => { console.error("Error:", error); alert("Error submitting event. Please try again."); }); }); } });