Add email validation to Gravity Forms forms
On a WordPress site with Gravity Forms, add the widget script to your footer and the short attach script, and it will check every email field on the page. For a check on the server, the free SimpleVerifier WordPress plugin supports Gravity Forms.
Before you start
You need a way to add code to your site footer, such as your theme's footer scripts setting or a header and footer plugin.
Setup
- Find where your site adds footer scripts: your theme's footer scripts setting, or a plugin that adds code to the site footer.
- Paste the snippet below into the footer scripts box (or into a Custom HTML block placed on the page) and save.
- Reload the page that shows your form.
- Open the published page (not the editor preview) and type jane@gmial.com into the field. You should see a suggestion to use gmail.com under it. Try x@mailinator.com to see the disposable-address error.
<script src="https://simpleverifier.com/widget.js" defer></script>
<script>
// Turns the widget on for every email field on the page, including fields the builder adds later.
function svAttachAll() {
if (!window.SimpleVerifier) return;
document.querySelectorAll('input[type="email"]').forEach(function (input) {
SimpleVerifier.attach(input);
});
}
document.addEventListener("DOMContentLoaded", function () {
svAttachAll();
new MutationObserver(svAttachAll).observe(document.body, { childList: true, subtree: true });
});
</script>Limits on Gravity Forms
- Gravity Forms lets you add a CSS class to a field but not an attribute, which is why the snippet attaches the widget by field type.
- If the form is loaded with AJAX, the snippet watches for the new field and attaches it.
- The widget cannot confirm a mailbox exists. The WordPress plugin does that on the server with your API key, on Pro or higher.
- Blocking a submit relies on the browser's own form validation. If a builder sends the form with its own script instead, the hint under the field still appears but the form may go through, so test on the published page.
Check that the mailbox exists
The widget checks format, typos, throwaway domains and role addresses in the browser. It cannot tell whether a mailbox exists, because that needs an API key and anything in a web page can be read by visitors. For that, call the API from the server that receives the form. See the API docs, the full form widget page with Node, PHP and Python examples, and pricing.
Related: WordPress plugin.
Common questions
- Should I use the widget or the WordPress plugin?
- The widget is free and checks in the browser. The plugin checks on your server with your own API key, so it can confirm the mailbox exists. They can run together.
- Does it work with other WordPress form plugins?
- The widget attaches to any email input on the page, so it works with most. The plugin also lists Contact Form 7 and WPForms.
- Do I need to edit the Gravity Forms field settings?
- No. The snippet finds fields of type email itself.
- Is the form widget free?
- Yes. The widget runs in the visitor's browser, needs no account or API key and has no usage limit. Checks that confirm the mailbox exists use the SimpleVerifier API from a server, which comes with Pro, Business and Agency, from $39/month.