1
1 Comment

Hugo form

To create a contact form using Hugo, you can follow these steps:

  1. Open your Hugo project folder in a code editor.
  2. Create a new HTML file for your contact form. You can name it something like contact.html and save it in the layouts directory.
  3. In the contact.html file, you can add the HTML markup for your contact form. Here's a basic example:
<form method="post" action="/contact/submit">
  <div>
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required>
  </div>
  <div>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>
  </div>
  <div>
    <label for="message">Message:</label>
    <textarea id="message" name="message" required></textarea>
  </div>
  <div>
    <input type="submit" value="Submit">
  </div>
</form>
  1. Save the contact.html file.

  2. In your Hugo project, create a new content file for the contact page. You can name it contact.md and save it in the content directory. Add the necessary front matter and content to the file. For example:

---
title: "Contact"
date: 2023-07-12
---

Please use the form below to get in touch with us.
{{< rawhtml >}} {{ partial "contact.html" . }} {{< /rawhtml >}}

6. Save the `contact.md` file.

7. Run the Hugo server to preview your changes. In your terminal, navigate to your Hugo project directory and run the command `hugo server`.

8. Open your web browser and visit `http://localhost:1313/contact` (or the appropriate URL for your Hugo server). You should see your contact form rendered on the page.

9. You can customize the form's appearance and add any additional fields or validation as needed.

10. To handle the form submission, you'll need to create a form processing endpoint in your Hugo project. This typically involves creating a new template file and specifying the form action URL accordingly. You can use a server-side language or a form handling service to process the form data and send emails.

Remember to update the form action URL (`action="/contact/submit"`) in the HTML markup to point to the appropriate endpoint for processing form submissions on your server.

[Hugo forms](https://fabform.io/a/hugo-contact-form)
on July 12, 2023
Trending on Indie Hackers
6 weeks solo, 2 rejections, finally live but nobody told me marketing would be this hard User Avatar 108 comments Building ExpenseSpy solo, no funding — launching June 17 on iOS & Android User Avatar 45 comments I built a $5/1k-listing CRE data API because CoStar is overkill for first-pass scans User Avatar 18 comments Day 7: 51 people answered my question. I wasn't ready for what they said. User Avatar 18 comments Building LinkCover – Day 3: Payment is live. No more building, time to sell. User Avatar 15 comments I Was Bypassing Every App Blocker, So I Built One That Fights Back User Avatar 11 comments