Discord Webhook Forms for Static Sites
You can find two versions of the form, and all components, on Codepen here. The version I'm sharing here features hardly any CSS styling. This allows you to fill in your own and for your site’s existing theme to apply to the form fields and such. There's another version on Codepen with... significantly more CSS. Anyways...
We all really do need a contact form on our website. True, we could just toss our email address up there, but that’s a bit of a hassle for visitors who might just want to type in a quick question. I prefer to post a contact form for short inquiries, a guestbook/askbox for public questions, and my email for longer inquiries.
There’s a lot of different options for contact forms. A lot of third-party sites offer solutions for this. Initially, on my other site, I used one of those, but it was just ridiculous, had advertisements, and was messy, not easy to customize. I hunted until I discovered how to send messages from my website to a Discord server of my own creation, where I can easily get alerts about them. Naturally, this works amazingly for me and others like me who constantly have Discord running in the background of their devices.
The Discord webhook forms you see below are based on the work of Goblin-Heart, also known as Sadgrl on neocities. You can find her version of the code here. I didn’t find anything on her site about not doing any heavy modifications and resharing it, so I’ve done that. If I’m in error and Goblin-Heart disapproves, she is welcome to contact me and I’ll be respectful of her wishes immediately.
My version features a litmus test (of a rudimentary sort) to ensure both that all portions of the form are filled out, and that the email address that the user types in actually matches the proper format. While this is far from an actual CAPTCHA, it will likely cut down on the possibility of some person or bot just typing gibberish in your form. I understand that CAPTCHAs are extremely useful and a lot of people do worry about shoving a webhook out there like this, but honestly? My other site has had 80K visits (according to neocities itself, though many were probably not genuine visitors) since last November, and hasn’t had any Discord spam. If I learn to set up a CAPTCHA (unlikely), I'll share it!
It also, rather than using an alert popup message, will simply erase the form upon receipt of the message. It then displays a message (customizable) thanking the visitor in place of the form. It also includes an element just below the form which will become visible if the form contents do not match the stipulations mentioned before (ie, all fields and email syntax). This part just hisses at the visitor and lets them know what they ought to do next.
The Discord message itself is also formatted slightly differently, with the date removed (given that timestamps are native to Discord) and the addition of a title to each (“NEW SITE MESSAGE”). There’s some bolding of the text in order to make things more legible within the app, too. You can play with this if you look into Discord’s markdown system a bit.
Creating Discord Webhooks
You don’t need Discord Nitro to make these, and no, don’t ask me what a webhook even is. At least, don’t ask me to explain it in my own words. I assume it’s simply a term for something that connects the app to the web. I don’t particularly care at this juncture. Sorry. If you feel like explaining it to me, feel free, but please don’t be rude - we all start somewhere. I’m learning more day by day.
Either way, Discord webhooks are easy to create. Wondering how to create a webhook? I suggest reading Discord’s tutorial - you don’t have to read much, just how to make one, and snag the URL. That (initially, at least) seems to cover it for getting this to work.
I recommend creating a new server to make the webhook, all your own, just for your site. Perhaps add other collaborators, if there are any, or otherwise, keep it to yourself. All of the messages sent by the web form will appear in the server in a channel you create. You’ll want it private for that reason, unless you want other people (in the server) seeing them.
So, create a channel (presumably just) for the web form (It doesn’t matter what you call it), and create a webhook for that channel. The URL of the webhook can then be copied and inserted into the Javascript snippets that I’ll provide later in this article.
CSS
As noted above, there isn’t CSS for this, really, except for a bit that assures the form itself functions properly and nothing overlaps, no elements crash into each other and explode, etc… you may, of course, customize much further. The below list includes everything specific to the form.
HTML
The HTML for this is rather simple, but can be customized easily - that's the point of keeping it simple. One important aspect, though? This whole thing uses jQuery, so be sure to include the following like just before the </body> tag on any page where you use this...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>Javascript
This is, essentially, the same as the previous one. I’m basically copying from the earlier part of this page for that reason, just in case you skipped it. The fields containing the words “darling,” “dearest” etc are all messages to the visitor, which can be changed.
The usual rules about the contents of Javascript HTML apply here, though. Please add a \ just before any quotation marks, double or single, when writing for these fields. You can use this weak little converter I made to (attempt) to do this automatically, as well as removing line breaks.
Be absolutely sure that you replace the line indicated with your Discord webhook URL, or the form will be completely useless.