Integrations · Websites and CMS
Validate emails in Squarespace forms
Check the email field of your Squarespace forms before they are sent. One snippet in Code Injection loads the form guard: when a visitor has finished typing an address, it offers a one-click fix for typos such as gmial.com and stops the form only when the address cannot receive mail or is a throwaway inbox. It is built for form blocks, newsletter blocks and forms in a lightbox. If anything goes wrong (no credits left, a slow answer, the script blocked), the form is sent as usual.
Status: set up from this page. There is no Squarespace Extensions listing: you paste the snippet below into your site's Code Injection.
Before you start
A Squarespace plan with code injection. Squarespace offers code injection on its Core, Plus and Advanced plans and some older ones (Squarespace's help on code injection). Code injection never runs on Squarespace's checkout pages.
A browser key. In the dashboard, open API keys, choose Create key and pick On a public web page under Where will you use this key?. Give it:
- Allowed origins: your site, such as
https://www.example.comandhttps://example.com, plus yoursquarespace.comaddress if you test there. - Daily credit cap: a little above the sign-ups you get on a busy day.
The key sits in your page's source, so treat it as public: it can only validate addresses, only from your site's pages, and never past its cap (what a browser key protects).
- Allowed origins: your site, such as
Add it
- In Squarespace, open the Pages panel and click Custom Code at the bottom, then Code Injection (on a version 7.0 site: Website Tools, then Code Injection).
- Paste the snippet into Footer, with your key in place of
YOUR_BROWSER_KEY:
<!-- email-validation.org form guard for Squarespace forms: https://email-validation.org/docs/form-guard/ -->
<script src="https://email-validation.org/guard/v1.js" data-key="YOUR_BROWSER_KEY" defer></script>
<script>
// Some Squarespace form blocks render the Email field as a text field: mark those for the form guard too.
(() => {
const SEL = 'form input[name="email"],form input[autocomplete="email"],form input[x-autocompletetype="email"]';
function add(el) {
if (el.type !== 'text' || el.hasAttribute('data-ev-guard')) return;
el.setAttribute('data-ev-guard', '');
if (window.EVGuard) window.EVGuard.attach(el);
}
function scan(root) {
if (root.matches?.(SEL)) add(root);
root.querySelectorAll(SEL).forEach(add);
}
scan(document);
new MutationObserver((records) => {
records.forEach((r) => {
r.addedNodes.forEach((n) => {
if (n.nodeType === 1) scan(n);
});
});
}).observe(document.documentElement, { childList: true, subtree: true });
})();
</script>- Save.
- Test it on your live site in a private window (Squarespace may not run custom code while you are logged in), with the free test addresses:
no_mailbox@sandbox.email-validation.orgshows the message and stops the form, andlikely_typo@sandbox.email-validation.orgalso offers a fix. To see a form go through, use an address of yours that receives mail: a test address that goes through (accepted@sandbox.email-validation.org) would get the form's emails, such as a newsletter's confirmation, and the bounce hurts your sender.
To guard the forms of one page only, paste the snippet's two <script> tags (without the comment line) into that page's Page Header Code Injection instead (hover over the page in the Pages panel, click its gear icon, then Advanced), not into the site's Footer. Squarespace advises against other HTML in that field.
Settings
Add these to the first <script> tag of the snippet:
| Attribute | What it does |
|---|---|
data-region="eu" | Sends the checks to https://api-eu.email-validation.org, if your account processes data in the EU only (EU data residency). |
data-stop="invalid" | The results that stop the form: invalid and disposable by default; any of invalid disposable catch_all, or none. valid and unknown always go through. |
data-msg-invalid, data-msg-disposable, data-msg-catch-all, data-msg-suggest | Your own wording. |
The full list is on the form guard page.
Good to know
- Every email field in every form on the page is guarded. Squarespace shows some Email fields as plain text fields; the snippet's second part hands those to the form guard too. To keep it off a page (one with a sign-in form, say), use the per-page placement above instead of the site's Footer.
- Each address is checked once per page view, and only when the visitor has typed a whole address.
- The address goes from the visitor's browser to our API only to be checked (what it is used for).
Related
- Form guard: how the script works, its options and styling.
- Test addresses: every result, free.