Submit a form without redirecting

By default a form post leaves the page. To stay on the page, send the form with fetch and show your own message. Ask for JSON with the Accept header so you get a result you can read.
  1. 1

    Create a free FormTango account and add a form. Copy its endpoint, which looks like https://formtango.com/f/YOUR_FORM_ID.

  2. 2

    Add this script after your form.

  3. 3

    Submit the form once. The submission appears in your FormTango inbox and you get an email.

html
<form id="contact" action="https://formtango.com/f/YOUR_FORM_ID" method="POST">
  <input type="email" name="email" required>
  <textarea name="message" required></textarea>
  <button type="submit">Send</button>
  <p id="contact-status" role="status"></p>
</form>

<script>
  const form = document.getElementById('contact');
  const status = document.getElementById('contact-status');

  form.addEventListener('submit', async (event) => {
    event.preventDefault();
    const response = await fetch(form.action, {
      method: 'POST',
      headers: { Accept: 'application/json' },
      body: new FormData(form),
    });
    const result = await response.json();
    if (result.ok) {
      form.reset();
      status.textContent = 'Thanks! Your message has been sent.';
    } else {
      status.textContent = result.error || 'Something went wrong. Please try again.';
    }
  });
</script>

Good to know

  • Because the form still has an action, it works the ordinary way if JavaScript fails to load.
  • Want this without writing the script? The FormTango drop-in script does the same with one attribute.

What you get

  • Every submission saved in an inbox you can search and export.
  • An email for each one, with the visitor's address as the reply-to.
  • Spam filtering without making visitors solve a puzzle.
  • Problems? See troubleshooting.

Related guides

HTML form to emailContact form without a backendHTML file upload formStop contact form spamA form backend for AI coding agents

Last reviewed November 19, 2026.