Detected form widget enter key submits form twice: a fix guide

Fix the detected form widget enter key submits form twice problem: audit handlers, set button types, add idempotency, then run a four-path test pass.

James HollowayWeb Development Lead7 min read

If the detected form widget enter key submits form twice, the duplicate usually is not the embed script itself. Pressing Enter in a text input triggers the browser's built-in implicit submission, and that native request can collide with a second submit listener, an untyped button, or a retry you added by hand. The result is two records, a doubled confirmation email, or a GET payload in the URL followed by a POST.

This guide walks through the diagnosis in order: what you are seeing, how implicit submission works, where the second path comes from, five fixes with code, and a test script you can repeat after the widget is installed on your registered domain.

What "submits twice" actually looks like

Start by naming the symptom precisely, because each shape points to a different cause:

  • Two records in your inbox or sheet. Two requests reached the server. Either two handlers fired, or one handler fired and something replayed the request.
  • A confirmation appears, then a page reload. Your JavaScript handler ran, but the native submission continued because preventDefault() was missing or ran on a different handler.
  • The URL shows ?name=...&email=... after the reload. The form used method="GET" (or had no method), so the browser appended the data to the URL instead of sending a body. The MDN guide to sending and retrieving form data documents this: with GET, the data is appended to the URL as name/value pairs, while POST puts it in the request body.
  • Two records only on mobile. Mobile keyboards often dispatch Enter differently from physical keys; see the test script below.

Write down which one you see before touching code. Fixing a client-side double handler will not help if the server is processing one request twice.

How implicit form submission works when Enter is pressed

When a form has a submit button and the visitor presses Enter inside a single-line text input, the browser activates that submit button on the visitor's behalf. That is normal HTML behavior, not an enhancement.

Two consequences matter for the same bug:

  1. Any control that submits participates. That includes <button> elements inside the form and <input type="submit">. A <button> with no type attribute inside a form defaults to type="submit", so a "Show more" or "Clear" button silently becomes a second submit control.
  2. Validation runs before the request goes out. Native HTML constraints such as required, minlength, pattern and type="email" block submission and show an error message instead. MDN's client-side form validation guide notes that when an element is invalid, the browser blocks the submission and displays an error.

That second point is why deleting native validation to "stop the retry" is the wrong fix: a visitor who gets blocked may press Enter again, and if your handler has already fired once outside the validation path, you get an extra request.

Why the duplicate is usually a second handler or an untyped button

Before blaming the embed, check three things in your own markup. In our experience on lead forms, the duplicate lives in one of these places:

  • Two listeners. Your original script attaches a submit listener, and a template, framework or leftover snippet attaches another. Both run, both send.
  • A button without type. Secondary controls like "Calculate" or "Add another" submit the form because the default type inside a form is submit.
  • A handler that calls form.submit() or re-dispatches the event while the native path is also allowed to continue.

If your form already worked before the widget was installed, compare the DOM before and after: the widget connects the existing form, so your handler inventory should be unchanged. If it changed, the duplicate is in your code, not the embed.

Related reading on this site: HTML form validation for static site contact forms covers keeping native constraints intact, and the detected form widget honeypot spam protection guide shows how hidden fields inside the same form are meant to behave.

Step 1: Audit the form

Inspect the rendered form in DevTools and list every element that can fire a submission:

const form = document.querySelector('form');
console.log('buttons:', [...form.querySelectorAll('button')].map(b => ({
  text: b.textContent.trim(), type: b.type, hasAttr: b.hasAttribute('type')
})));
console.log('submit inputs:', form.querySelectorAll('input[type="submit"]').length);
console.log('method:', form.method, 'action:', form.getAttribute('action'));

b.type returns the effective type, so a button with no attribute shows submit — that is your culprit list. Also search your bundled JavaScript for addEventListener('submit' and onsubmit. If two matches attach to the same form, you have found the duplicate path.

Step 2: Give each button an explicit type

Separate real submit controls from secondary actions:

<form action="/submit" method="post">
  <label for="email">Email</label>
  <input id="email" name="email" type="email" required>

  <button type="submit">Send request</button>
  <button type="button" id="add-note">Add another line</button>
</form>

With type="button" on the secondary control, Enter in the email field can only trigger the real submit button. Re-run the audit snippet: every button should now show an explicit type.

Step 3: Make your own handler consistent

Pick one path and document it. If you handle submission with JavaScript, prevent the native request once:

form.addEventListener('submit', async (event) => {
  event.preventDefault();
  if (form.dataset.submitting === 'true') return;   // guard against re-entry
  form.dataset.submitting = 'true';
  try {
    await sendToEndpoint(new FormData(form));
  } finally {
    form.dataset.submitting = 'false';
  }
});

The re-entry guard matters because a fast double Enter press, or a mobile keyboard that sends Enter twice, fires the listener twice. If instead you rely on native submission, remove your JavaScript handler entirely rather than leaving it to also call fetch.

Step 4: Add server-side protection

Client-side guards can be bypassed, so treat the request as possibly repeated. Embed a unique token in the form and reject or ignore repeats:

<input type="hidden" name="submission_id" value="a7f3c9e1-...">

On the server, store the token when the request is accepted. If the same token arrives again, return the original confirmation without creating a second record — the idempotency pattern. This covers the case where the browser genuinely sends two POSTs, which no preventDefault() can undo after the fact. It also matches the MDN warning that server-side validation and checks are required because client-side validation is too easy to bypass.

Step 5: Keep native validation intact

Do not strip required or type="email" to make the double submit "go away". A blocked Enter press is correct behavior; the page then shows the error and waits. Pair native validation with clear inline errors as described in contact form error messages that help visitors fix and resubmit, so a blocked visitor is not tempted to mash Enter and queue a retry.

Test script: four submission paths

Run this after the widget is installed, on the registered domain, in at least one desktop and one mobile browser:

  1. Click the submit button with the mouse once.
  2. Focus a text input, press Enter once.
  3. Focus a <textarea>, press Enter — confirm a newline is inserted and nothing is submitted.
  4. On a phone, use the keyboard's Enter/Go key.
  5. Press Enter twice quickly in a text input.
  6. Trigger native validation (clear a required field), press Enter, then fix it and press Enter again.

For each path, watch the DevTools Network tab (documented by MDN as the place to inspect request payloads) and count requests. One submission, one request; anything else fails the test.

Regression checklist after installing the widget

  • Every <button> inside the form has an explicit type.
  • Exactly one submit listener is attached to the form.
  • The form method is POST for anything containing personal data.
  • A unique submission_id token is present and enforced server-side.
  • Native validation attributes are still on every field that needs them.
  • Hidden fields (consent, honeypot) are present in the submitted payload once each.
  • The four-path test script passes on desktop and mobile.

When the duplicate is intentional

Before deleting code, ask whether a repeat submission is legitimate. A visitor who edits an order and resubmits, or who fixes a validation error after a partial failure, should be able to send again. Distinguish a bug from a feature by checking the token: two different tokens are two deliberate submissions; two hits with the same token are a bug. Only then harden the guard.

Where to go next

Once the double submit is gone, confirm the rest of the form behaves: labels, consent wording, redirect and confirmation behavior. The Detected Form widget connects the HTML form you already run, so your fix stays in your markup and your server — the embed does not need to be rebuilt.

  • detected form widget enter key submits form twice
  • forms
  • detected form
  • validation
  • troubleshooting

Written by

James Holloway

Web Development Lead at WidgetJar

Keep reading

Get started

Your next lead is one line away.

Pick a design, make it yours and paste a single script tag. Every widget type is included, and you do not need a credit card to start.

<script src="https://cdn.widgetjar.com/wj-assets/embed.js" defer></script>