Skip to content

Instantly share code, notes, and snippets.

@Irishgeoff11
Created October 11, 2023 05:07
Show Gist options
  • Save Irishgeoff11/376f6ac42b63ee67756933dd9f3bd684 to your computer and use it in GitHub Desktop.
Save Irishgeoff11/376f6ac42b63ee67756933dd9f3bd684 to your computer and use it in GitHub Desktop.
Hugo forms
To create a form in a Hugo static site, you can follow these steps:
1. **Create a New Page**: Start by creating a new Markdown file in your Hugo project where you want the form to appear. For example, you can create a file named `contact.md` in your content directory.
2. **Front Matter**: In the Markdown file, add front matter at the top. This front matter defines the page's metadata, and you can also include form-related information. Here's an example:
```markdown
---
title: "Contact Us"
date: 2023-10-11
form: true
---
```
3. **Form HTML**: Below the front matter, you can add your form's HTML code. Hugo doesn't provide a built-in form system, so you can use plain HTML for your form or integrate a third-party form service, like Formspree or Netlify Forms.
```markdown
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<textarea id="message" name="message" rows="4" required></textarea>
<input type="submit" value="Submit">
</form>
```
4. **Processing the Form**: To handle form submissions, you'll need server-side code. If your Hugo site is static, you can use third-party services like Formspree or Netlify Forms to process and collect form data. These services will provide you with an endpoint to which the form data can be sent.
5. **Customize Styling**: You can style your form using CSS to match your site's design.
6. **Render the Page**: Build your Hugo site to generate the static HTML pages, including the one with the form.
7. **Publish**: Upload your Hugo site, including the new form page, to your web server.
Remember that Hugo is a static site generator, so it doesn't process forms itself. You'll need a server or a third-party service to handle form submissions.
@Irishgeoff11
Copy link
Author

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