question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Netlify Adapter: Netlify Forms don't work

See original GitHub issue

Describe the bug Netlify Forms don’t work in a Svelte component if setup with this approach and using the Netlify adapter.

_Edit: For a workaround/fix see the comment below https://github.com/sveltejs/kit/issues/942#issuecomment-828726791_

To Reproduce

  1. Setup a Netlify Form as described here and more specifically here:
    • Create a Netlify “form detection helper”. Something like:
      <!-- "/static/netlify-form-helper.html" -->
      <form name="test" netlify netlify-honeypot="bot-field" hidden>
          <input type="text" name="name" />
          <input type="email" name="email" />
          <textarea name="message"></textarea>
      </form>
      
    • Create the Svelte form component:
      <!-- "/src/routes/test-form.svelte" -->
      <form name="test" method="post" action="/success">
          <input type="hidden" name="form-name" value="test" />
          <input type="text" name="bot-field" />
          <p>
              <label>Your Name: <input type="text" name="name" /></label>
          </p>
          <p>
              <label>Your Email: <input type="email" name="email" /></label>
          </p>
          <p>
              <label>Message: <textarea name="message" /></label>
          </p>
          <p>
              <button type="submit">Send</button>
          </p>
      </form>
      
    • Ensure Netlify’s form processing is enabled.
  2. If everything is setup correctly, Netlify should tell you that it detected a form named “test” for your site.
  3. Now navigate to your https://example.tld/test-form and send a submission.
  4. Even when taking care of all troubleshooting tips from here and here, neither verified nor spam submissions show up in Netlify’s form overview.

Expected behavior A form submission should be shown in Netlify’s form overview if submitted via my SvelteKit webapp.

Information about your SvelteKit Installation:

Severity Blocker, as Netlify’s simple form handling is one of the key benefits I’m using it for. However, right now I cannot use Netlify Forms with SvelteKit.

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
Blumedcommented, Oct 19, 2021

Recent update has changed how you did the svelteconfig.js @sw-yx

		prerender: {
			crawl: true,
			enabled: true,
			onError: 'continue',
			entries: ['*'],
		},
3reactions
kvn-shncommented, Apr 28, 2021

So I played around with it a little more and can now definitely say that Netlify forms are not working out-of-the-box when using a custom success message. But I have good news as well: It’s working fine when prerendering the “success” page too!

TL;DR In the following a small conclusion…

How to make Netlify forms work in SvelteKit

  1. Add the following to svelte.config.cjs (as described in @sw-yx blog post):
    prerender: {
        crawl: true,
        enabled: true,
        force: true,
        pages: ['*']
    }
    
  2. Create your Netlify HTML form as described here, e.g. as /routes/contact.svelte. (Don’t forget to add the “form-name” input!)
  3. Tell SvelteKit to prerender your contact.svelte page component by adding:
    <script context="module">
        export const prerender = true;
    </script>
    
  4. If your Netlify form has a custom success message, e.g. something like <form name="contact" netlify method="POST" action="/success">, then:
    • Ensure /success points to a proper Svelte page component
    • In it add the same prerender hint as in step 3
  5. That’s it! 😃

(This issue could even be closed now. Or should we add these steps to the readme?!)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Netlify Form not getting recognized in svelte-kit app - Support
Describe the bug Netlify Forms don't work in a Svelte component if setup with this approach and using the Netlify adapter.
Read more >
Netlify Forms Not Working - Support
I'm trying to get contact form submissions working, but they are not sending. I've tried: Changing attribute data-netlify="true" to netlify ...
Read more >
Easy HTML Forms in SvelteKit with Netlify Forms
Netlify Adapter. SvelteKit uses the concept of adapters to adapt the application to the platform you are deploying to. For Netlify, we can...
Read more >
Form troubleshooting tips - Netlify Docs
If you're not finding new form submissions in your Verified submissions list for updated or newly added forms, ensure that form detection is...
Read more >
Netlify form doesn't work with Sveltekit - Support
If you still can't get unstuck can you please share your site name along with the steps you have taken to implement the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found