Skip to content

Instantly share code, notes, and snippets.

@irishgeoff20
Created October 5, 2023 09:55
Show Gist options
  • Save irishgeoff20/41ad9a1af50634feb967de0608555c99 to your computer and use it in GitHub Desktop.
Save irishgeoff20/41ad9a1af50634feb967de0608555c99 to your computer and use it in GitHub Desktop.
neocities forms
Neocities is a web hosting service that allows users to create and host their own websites. While Neocities provides the basic infrastructure for creating and hosting websites, it does not offer built-in form-handling capabilities like some other web hosting services or content management systems (CMS). However, you can implement forms on your Neocities-hosted website by using HTML and JavaScript.
Here's a basic example of how you can create a simple contact form on your Neocities website:
1. **Create the HTML Form**:
```html
<!DOCTYPE html>
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<h1>Contact Us</h1>
<form id="contact-form">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message" rows="4" cols="50" required></textarea><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
```
2. **Add JavaScript for Form Submission**:
You can use JavaScript to handle the form submission. Here's a simple example using JavaScript and the Fetch API to send form data to a server:
```html
<script>
document.getElementById('contact-form').addEventListener('submit', function (e) {
e.preventDefault();
const formData = new FormData(this);
fetch('/your-server-endpoint', {
method: 'POST',
body: formData
})
.then(response => {
if (response.ok) {
// Handle success (e.g., show a success message)
} else {
// Handle error (e.g., display an error message)
}
})
.catch(error => {
// Handle network error
});
});
</script>
```
Replace `'/your-server-endpoint'` with the actual URL where you want to handle the form data on your server.
3. **Set Up Server-Side Processing**:
On your server, you will need to create a script (e.g., in PHP, Python, Node.js, etc.) to handle the form data sent from the HTML form. This script should process the data and, if necessary, send email notifications or perform other actions based on the form submission.
Keep in mind that handling form submissions on your own server may require some server-side scripting knowledge. Additionally, you should implement security measures to prevent spam and protect sensitive data.
Remember to replace the placeholders in the code with your actual form fields, server endpoint, and any other relevant details specific to your website and requirements.
@irishgeoff20
Copy link
Author

That was very helpful to add neocities forms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment