Docs / Frameworks
Contact form for Hugo
A Hugo partial that emails you every submission, with the form ID kept in your site config.
{{/* layouts/partials/contact-form.html
In hugo.toml: [params] wrenformId = "YOUR_FORM_ID" */}}
<form action="https://wrenform.com/f/{{ site.Params.wrenformId }}" method="POST">
<input type="text" name="name" required>
<input type="email" name="email" required>
<textarea name="message" required></textarea>
<input type="text" name="_honey" style="display:none" tabindex="-1" autocomplete="off">
<button type="submit">Send</button>
</form>Steps
- Create a form and copy its form ID from the Setup page.
- Add the ID to your site config:
[params]
wrenformId = "YOUR_FORM_ID"- Save the partial as
layouts/partials/contact-form.html. - Call it from a template, for example
layouts/_default/contact.html:{{ partial "contact-form.html" . }}. - Build and deploy as usual. Then add your site's origin under Allowed origins in the form's settings.
Hugo has no server, and it doesn't need one here: the visitor's browser posts the form to Wrenform.
Use it inside Markdown content
Partials don't run inside Markdown pages. To place the form in content/contact.md, wrap the partial in a shortcode:
{{ partial "contact-form.html" . }}Then write {{< contact-form >}} in the page where the form should appear.
Your own thank-you page
Add a hidden _redirect field with an absolute URL built by Hugo:
<input type="hidden" name="_redirect" value="{{ "thanks/" | absURL }}">The URL must be on one of the form's allowed origins, or we ignore it. You can also set Redirect to in the form's settings instead. See redirects.
Test it
Run hugo server, open the page and send the form. Check your dashboard and inbox. While you test on localhost, leave Allowed origins empty or add http://localhost:1313.
Common problems
- The form action ends in
/f/.site.Params.wrenformIdis empty. Check the parameter name and that it sits under[params]. _redirectis ignored.absURLuses yourbaseURL. Onhugo serverthat's localhost, which isn't in your allowed origins.- The shortcode prints nothing. The shortcode file name must match the name you use in the page.
Next steps
- My form isn't working: symptom, cause and fix.
- Spam: how the filters work.
- Fields: subjects, reply-to, lists and checkboxes.
- HTML guide: the strict Content-Security-Policy version.