Skip to content

Use Submitry with Etch

This page gives you a contact form to paste into an Etch page. It is plain HTML, so it also works in any other builder or static site.

The form posts to your Submitry Worker. Submitry has no special attributes: the action address and the name of each field are all it needs. See Add your first form for the background.

  • A client site and a form in the admin screen. Open the form’s Embed tab and note the form address (https://YOUR_WORKER/f/FORM_ID).
  • The form fields name, email and message, and a honeypot called website. Use Import from HTML on the form after you paste the snippet, and Submitry picks them up.
  • For Turnstile: a free site key from the Cloudflare dashboard, and the matching secret saved as a Turnstile connection in Submitry.

Copy this into your Etch page and replace YOUR_WORKER, FORM_ID and YOUR_TURNSTILE_SITE_KEY. Delete the Turnstile block if you do not use it.

<!--
Submitry contact form for Etch. Replace the two values in capitals:
FORM_ID the form id shown in the Submitry admin screen (Embed tab)
YOUR_WORKER the address of your Submitry Worker, for example submitry.your-account.workers.dev
The field names (name, email, message) and the honeypot name (website) must match the form's
settings in Submitry. Delete the Turnstile block if the form does not use Turnstile.
-->
<form
class="contact-form"
action="https://YOUR_WORKER/f/FORM_ID"
method="post"
data-submitry
>
<div class="contact-form__field">
<label class="contact-form__label" for="contact-name">Name</label>
<input class="contact-form__input" id="contact-name" name="name" type="text" autocomplete="name" required />
<p class="contact-form__error" id="contact-name-error" hidden></p>
</div>
<div class="contact-form__field">
<label class="contact-form__label" for="contact-email">Email</label>
<input class="contact-form__input" id="contact-email" name="email" type="email" autocomplete="email" required />
<p class="contact-form__error" id="contact-email-error" hidden></p>
</div>
<div class="contact-form__field">
<label class="contact-form__label" for="contact-message">Message</label>
<textarea class="contact-form__input contact-form__input--area" id="contact-message" name="message" rows="6" required></textarea>
<p class="contact-form__error" id="contact-message-error" hidden></p>
</div>
<!-- Honeypot. Humans never see it. The name must match "honeypot" in the form settings. -->
<div class="contact-form__trap" aria-hidden="true">
<label for="contact-website">Leave this field empty</label>
<input id="contact-website" name="website" type="text" tabindex="-1" autocomplete="off" />
</div>
<!-- Cloudflare Turnstile. The widget adds the field cf-turnstile-response by itself. -->
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<div class="cf-turnstile contact-form__turnstile" data-sitekey="YOUR_TURNSTILE_SITE_KEY"></div>
<button class="contact-form__button" type="submit">Send message</button>
<p class="contact-form__status" role="status" aria-live="polite" data-submitry-status></p>
</form>

The classes follow BEM (contact-form__input) and carry no styling until you add the stylesheet. Every field has a visible label, errors are tied to their field, and the status message is announced to screen readers.

Add this to your site’s styles. The values at the top (--contact-form-gap, --contact-form-error and so on) are custom properties. Point them at your own design tokens.

/* Styles for contact-form.html. BEM, no framework. Adjust the custom properties to your design tokens. */
.contact-form {
--contact-form-gap: 1rem;
--contact-form-border: currentColor;
--contact-form-error: #b00020;
--contact-form-focus: Highlight;
display: grid;
gap: var(--contact-form-gap);
max-width: 36rem;
}
.contact-form__field {
display: grid;
gap: 0.35rem;
}
.contact-form__label {
font-weight: 600;
}
.contact-form__input {
width: 100%;
padding: 0.65rem 0.8rem;
border: 1px solid var(--contact-form-border);
border-radius: 0.25rem;
background: transparent;
color: inherit;
font: inherit;
}
.contact-form__input--area {
resize: vertical;
}
.contact-form__input:focus-visible,
.contact-form__button:focus-visible {
outline: 3px solid var(--contact-form-focus);
outline-offset: 2px;
}
.contact-form__input[aria-invalid="true"] {
border-color: var(--contact-form-error);
}
.contact-form__error,
.contact-form__status--error {
color: var(--contact-form-error);
}
.contact-form__error,
.contact-form__status {
margin: 0;
font-size: 0.95rem;
}
/* Visually hidden but still in the DOM, so bots fill it. Do not use display:none. */
.contact-form__trap {
position: absolute;
left: -9999px;
width: 1px;
height: 1px;
overflow: hidden;
}
.contact-form__button {
justify-self: start;
padding: 0.7rem 1.4rem;
border: 0;
border-radius: 0.25rem;
background: CanvasText;
color: Canvas;
font: inherit;
font-weight: 600;
cursor: pointer;
}
.contact-form__button:disabled {
opacity: 0.6;
cursor: progress;
}

Without a script, the browser posts the form normally and Submitry sends the visitor to the thank-you page you set as successRedirect.

If you want the message to appear on the same page, save this as submitry-form.js on your own site and load it with defer.

// Optional. Sends any <form data-submitry> with fetch and shows the answer on the page.
// Without this script the form still works: the browser posts it normally and Submitry redirects
// to your thank-you page. Host the file on your own site (do not hotlink it).
(function () {
var forms = document.querySelectorAll('form[data-submitry]')
Array.prototype.forEach.call(forms, function (form) {
var status = form.querySelector('[data-submitry-status]')
var button = form.querySelector('button[type="submit"]')
var reasons = {
required: 'This field is required.',
invalid_email: 'Enter a valid email address.',
too_long: 'This is too long.',
}
function clearErrors() {
status.textContent = ''
status.classList.remove('contact-form__status--error')
Array.prototype.forEach.call(form.querySelectorAll('[aria-invalid]'), function (el) {
el.removeAttribute('aria-invalid')
el.removeAttribute('aria-describedby')
})
Array.prototype.forEach.call(form.querySelectorAll('.contact-form__error'), function (el) {
el.hidden = true
el.textContent = ''
})
}
function showFieldErrors(fields) {
var first = null
Object.keys(fields).forEach(function (name) {
var input = form.elements[name]
if (!input || !input.id) return
var note = document.getElementById(input.id + '-error')
if (!note) return
note.textContent = reasons[fields[name]] || 'Check this field.'
note.hidden = false
input.setAttribute('aria-invalid', 'true')
input.setAttribute('aria-describedby', note.id)
if (!first) first = input
})
if (first) first.focus()
}
form.addEventListener('submit', function (event) {
event.preventDefault()
clearErrors()
button.disabled = true
status.textContent = 'Sending...'
fetch(form.action, {
method: 'POST',
headers: { Accept: 'application/json' },
body: new FormData(form),
})
.then(function (response) {
return response.json().then(function (result) {
return { ok: response.ok, result: result }
})
})
.then(function (answer) {
if (answer.ok) {
status.textContent = answer.result.message || 'Thank you. Your message was sent.'
form.reset()
if (window.turnstile) window.turnstile.reset()
return
}
status.textContent = ''
if (answer.result.fields) {
showFieldErrors(answer.result.fields)
status.textContent = 'Please check the highlighted fields.'
} else {
status.textContent = answer.result.message || 'Something went wrong. Please try again.'
}
status.classList.add('contact-form__status--error')
if (window.turnstile) window.turnstile.reset()
})
.catch(function () {
status.textContent = 'Could not reach the server. Please try again.'
status.classList.add('contact-form__status--error')
})
.then(function () {
button.disabled = false
})
})
})
})()

The script sends the form with fetch, shows field errors next to the right field, and resets Turnstile after each try. It works on every form that has the attribute data-submitry.

These use the same styles and the same optional script as the contact form.

Submitry stores each signup and mails you. It is not a mailing list tool. To pass the address on to your newsletter service, add a webhook action to the form in Submitry.

<!--
Submitry newsletter signup for Etch. Replace YOUR_WORKER and FORM_ID.
Styles: use contact-form.css (the classes are shared). Optional script: submitry-form.js.
Submitry stores each signup and mails you. It is not a mailing list tool. To send the address on to
your newsletter service, add a webhook action to the form in Submitry.
Form settings in Submitry: fields email (required, type email) and name (optional), honeypot "website".
-->
<form
class="contact-form"
action="https://YOUR_WORKER/f/FORM_ID"
method="post"
data-submitry
>
<div class="contact-form__field">
<label class="contact-form__label" for="news-email">Email</label>
<input class="contact-form__input" id="news-email" name="email" type="email" autocomplete="email" required />
<p class="contact-form__error" id="news-email-error" hidden></p>
</div>
<div class="contact-form__field">
<label class="contact-form__label" for="news-name">First name <span>(optional)</span></label>
<input class="contact-form__input" id="news-name" name="name" type="text" autocomplete="given-name" />
<p class="contact-form__error" id="news-name-error" hidden></p>
</div>
<div class="contact-form__trap" aria-hidden="true">
<label for="news-website">Leave this field empty</label>
<input id="news-website" name="website" type="text" tabindex="-1" autocomplete="off" />
</div>
<!-- Consent: the notice sits next to the button, so clicking it is the agreement. Adapt the wording and link to your privacy policy. -->
<p class="contact-form__status">
By subscribing, you agree that we email you our newsletter. You can unsubscribe at any time. See the
<a href="/privacy/">privacy policy</a>.
</p>
<button class="contact-form__button" type="submit">Subscribe</button>
<p class="contact-form__status" role="status" aria-live="polite" data-submitry-status></p>
</form>
<!--
Submitry project inquiry form for Etch. Replace YOUR_WORKER, FORM_ID and YOUR_TURNSTILE_SITE_KEY.
Styles: use contact-form.css (the classes are shared). Optional script: submitry-form.js.
Form settings in Submitry: fields name, email (type email) and message are required; company and
budget are optional. Honeypot "website". Submitry does not check the options of the budget dropdown,
so change them freely. Tip: add a condition so a high budget is mailed to a different inbox.
-->
<form
class="contact-form"
action="https://YOUR_WORKER/f/FORM_ID"
method="post"
data-submitry
>
<div class="contact-form__field">
<label class="contact-form__label" for="inquiry-name">Name</label>
<input class="contact-form__input" id="inquiry-name" name="name" type="text" autocomplete="name" required />
<p class="contact-form__error" id="inquiry-name-error" hidden></p>
</div>
<div class="contact-form__field">
<label class="contact-form__label" for="inquiry-email">Email</label>
<input class="contact-form__input" id="inquiry-email" name="email" type="email" autocomplete="email" required />
<p class="contact-form__error" id="inquiry-email-error" hidden></p>
</div>
<div class="contact-form__field">
<label class="contact-form__label" for="inquiry-company">Company <span>(optional)</span></label>
<input class="contact-form__input" id="inquiry-company" name="company" type="text" autocomplete="organization" />
<p class="contact-form__error" id="inquiry-company-error" hidden></p>
</div>
<div class="contact-form__field">
<label class="contact-form__label" for="inquiry-budget">Budget <span>(optional)</span></label>
<select class="contact-form__input" id="inquiry-budget" name="budget">
<option value="">Prefer not to say</option>
<option value="under-5k">Under 5,000 EUR</option>
<option value="5k-15k">5,000 to 15,000 EUR</option>
<option value="over-15k">Over 15,000 EUR</option>
</select>
<p class="contact-form__error" id="inquiry-budget-error" hidden></p>
</div>
<div class="contact-form__field">
<label class="contact-form__label" for="inquiry-message">Tell us about the project</label>
<textarea class="contact-form__input contact-form__input--area" id="inquiry-message" name="message" rows="7" required></textarea>
<p class="contact-form__error" id="inquiry-message-error" hidden></p>
</div>
<div class="contact-form__trap" aria-hidden="true">
<label for="inquiry-website">Leave this field empty</label>
<input id="inquiry-website" name="website" type="text" tabindex="-1" autocomplete="off" />
</div>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<div class="cf-turnstile contact-form__turnstile" data-sitekey="YOUR_TURNSTILE_SITE_KEY"></div>
<button class="contact-form__button" type="submit">Send inquiry</button>
<p class="contact-form__status" role="status" aria-live="polite" data-submitry-status></p>
</form>

The matching settings for this snippet:

{
"fields": {
"name": { "required": true },
"email": { "required": true, "type": "email" },
"message": { "required": true, "maxLength": 5000 }
},
"protect": { "honeypot": "website", "turnstile": true },
"response": { "successMessage": "Thank you. Your message was sent.", "successRedirect": "https://your-site.com/thanks/" }
}
  1. Send a test message from the live page, not from the editor.
  2. In the admin screen, open the submission and check that the notification mail was sent.
  3. Send the form once with an empty field and once with a wrong email address, and check that the error shows next to the field.